Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
\#if 0 instead of comment
  • Loading branch information
luipir committed Feb 1, 2019
1 parent 461b31d commit 738ec79
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 62 deletions.
83 changes: 43 additions & 40 deletions src/core/raster/qgsmultibandcolorrenderer.cpp
Expand Up @@ -425,53 +425,56 @@ void QgsMultiBandColorRenderer::toSld( QDomDocument &doc, QDomElement &element,
// create base structure
QgsRasterRenderer::toSld( doc, element, props );

// TODO: the following commented code is necessary to avoid to export channelSelection in

#if 0
// TODO: the following jumped code is necessary to avoid to export channelSelection in
// case it's set as default value. The drawback is that it's necessary to calc band
// statistics that can be really slow depending on dataProvider and rastr localtion.
// this is the reason this part of code is commented and the channelSlection is
// always exported.
//
// before to export check if the band combination and contrast setting are the
// default ones to avoid to export this tags
// bool isDefaultCombination = true;
// QList<int> defaultBandCombination( { 1, 2, 3 } );

// isDefaultCombination = isDefaultCombination && ( usesBands() == defaultBandCombination );
// isDefaultCombination = isDefaultCombination && (
// mRedContrastEnhancement->contrastEnhancementAlgorithm() == QgsContrastEnhancement::StretchToMinimumMaximum &&
// mGreenContrastEnhancement->contrastEnhancementAlgorithm() == QgsContrastEnhancement::StretchToMinimumMaximum &&
// mBlueContrastEnhancement->contrastEnhancementAlgorithm() == QgsContrastEnhancement::StretchToMinimumMaximum
// );
// // compute raster statistics (slow) only if true the previous conditions
// if ( isDefaultCombination)
// {
// QgsRasterBandStats statRed = bandStatistics(1, QgsRasterBandStats::Min|QgsRasterBandStats::Max);
// isDefaultCombination = isDefaultCombination && (
// ( mRedContrastEnhancement->minimumValue() == statRed.minimumValue &&
// mRedContrastEnhancement->maximumValue() == statRed.maximumValue )
// );
// }
// if ( isDefaultCombination)
// {
// QgsRasterBandStats statGreen = bandStatistics(2, QgsRasterBandStats::Min|QgsRasterBandStats::Max);
// isDefaultCombination = isDefaultCombination && (
// ( mGreenContrastEnhancement->minimumValue() == statGreen.minimumValue &&
// mGreenContrastEnhancement->maximumValue() == statGreen.maximumValue )
// );
// }
// if ( isDefaultCombination)
// {
// QgsRasterBandStats statBlue = bandStatistics(3, QgsRasterBandStats::Min|QgsRasterBandStats::Max);
// isDefaultCombination = isDefaultCombination && (
// ( mBlueContrastEnhancement->minimumValue() == statBlue.minimumValue &&
// mBlueContrastEnhancement->maximumValue() == statBlue.maximumValue )
// );
// }
// if ( isDefaultCombination ):
// return

// look for RasterSymbolizer tag
QDomNodeList elements = element.elementsByTagName( QStringLiteral( "sld:RasterSymbolizer" ) );
bool isDefaultCombination = true;
QList<int> defaultBandCombination( { 1, 2, 3 } );

isDefaultCombination = isDefaultCombination && ( usesBands() == defaultBandCombination );
isDefaultCombination = isDefaultCombination && (
mRedContrastEnhancement->contrastEnhancementAlgorithm() == QgsContrastEnhancement::StretchToMinimumMaximum &&
mGreenContrastEnhancement->contrastEnhancementAlgorithm() == QgsContrastEnhancement::StretchToMinimumMaximum &&
mBlueContrastEnhancement->contrastEnhancementAlgorithm() == QgsContrastEnhancement::StretchToMinimumMaximum
);
// compute raster statistics (slow) only if true the previous conditions
if ( isDefaultCombination )
{
QgsRasterBandStats statRed = bandStatistics( 1, QgsRasterBandStats::Min | QgsRasterBandStats::Max );
isDefaultCombination = isDefaultCombination && (
( mRedContrastEnhancement->minimumValue() == statRed.minimumValue &&
mRedContrastEnhancement->maximumValue() == statRed.maximumValue )
);
}
if ( isDefaultCombination )
{
QgsRasterBandStats statGreen = bandStatistics( 2, QgsRasterBandStats::Min | QgsRasterBandStats::Max );
isDefaultCombination = isDefaultCombination && (
( mGreenContrastEnhancement->minimumValue() == statGreen.minimumValue &&
mGreenContrastEnhancement->maximumValue() == statGreen.maximumValue )
);
}
if ( isDefaultCombination )
{
QgsRasterBandStats statBlue = bandStatistics( 3, QgsRasterBandStats::Min | QgsRasterBandStats::Max );
isDefaultCombination = isDefaultCombination && (
( mBlueContrastEnhancement->minimumValue() == statBlue.minimumValue &&
mBlueContrastEnhancement->maximumValue() == statBlue.maximumValue )
);
}
if ( isDefaultCombination ):
return
#endif

// look for RasterSymbolizer tag
QDomNodeList elements = element.elementsByTagName( QStringLiteral( "sld:RasterSymbolizer" ) );
if ( elements.size() == 0 )
return;

Expand Down
46 changes: 24 additions & 22 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -1444,6 +1444,7 @@ bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
vendorOptionWriter( QStringLiteral( "contrast" ), QString::number( cF ) );
}

#if 0
// TODO: check if the below mapping formula make sense to map QGIS contrast with SLD gamma value
//
// add SLD1.0 ContrastEnhancement GammaValue = QGIS Contrast
Expand All @@ -1454,28 +1455,29 @@ bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
// [-100,0] => [0,1] and [0,100] => [1,100]
// an alternative could be scale [-100,100] => (0,2]
//
// if ( newProps.contains( QStringLiteral( "contrast" ) ) )
// {
// double gamma;
// double contrast = newProps[ QStringLiteral( "contrast" ) ].toDouble();
// double percentage = (contrast - (-100.0))/(100.0 - (-100.0));
// if ( percentage <= 0.5)
// {
// // stretch % to [0-1]
// gamma = percentage / 0.5;
// }
// else
// {
// gamma = contrast;
// }

// QDomElement globalContrastEnhancementElem = doc.createElement( QStringLiteral( "sld:ContrastEnhancement" ) );
// rasterSymolizerElem.appendChild( globalContrastEnhancementElem );

// QDomElement gammaValueElem = doc.createElement( QStringLiteral( "sld:GammaValue" ) );
// gammaValueElem.appendChild( doc.createTextNode( QString::number( gamma ) ) );
// globalContrastEnhancementElem.appendChild( gammaValueElem );
// }
if ( newProps.contains( QStringLiteral( "contrast" ) ) )
{
double gamma;
double contrast = newProps[ QStringLiteral( "contrast" ) ].toDouble();
double percentage = ( contrast - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
if ( percentage <= 0.5 )
{
// stretch % to [0-1]
gamma = percentage / 0.5;
}
else
{
gamma = contrast;
}

QDomElement globalContrastEnhancementElem = doc.createElement( QStringLiteral( "sld:ContrastEnhancement" ) );
rasterSymolizerElem.appendChild( globalContrastEnhancementElem );

QDomElement gammaValueElem = doc.createElement( QStringLiteral( "sld:GammaValue" ) );
gammaValueElem.appendChild( doc.createTextNode( QString::number( gamma ) ) );
globalContrastEnhancementElem.appendChild( gammaValueElem );
}
#endif
}
}
return true;
Expand Down

0 comments on commit 738ec79

Please sign in to comment.