From 738ec79d6dea756b2f8e1a2a590c33fe02b3d6cf Mon Sep 17 00:00:00 2001 From: Luigi Pirelli Date: Fri, 1 Feb 2019 15:44:30 +0100 Subject: [PATCH] \#if 0 instead of comment --- src/core/raster/qgsmultibandcolorrenderer.cpp | 83 ++++++++++--------- src/core/raster/qgsrasterlayer.cpp | 46 +++++----- 2 files changed, 67 insertions(+), 62 deletions(-) diff --git a/src/core/raster/qgsmultibandcolorrenderer.cpp b/src/core/raster/qgsmultibandcolorrenderer.cpp index 37161c80c5f6..15fe754a55cb 100644 --- a/src/core/raster/qgsmultibandcolorrenderer.cpp +++ b/src/core/raster/qgsmultibandcolorrenderer.cpp @@ -425,7 +425,9 @@ 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 @@ -433,45 +435,46 @@ void QgsMultiBandColorRenderer::toSld( QDomDocument &doc, QDomElement &element, // // 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 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 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; diff --git a/src/core/raster/qgsrasterlayer.cpp b/src/core/raster/qgsrasterlayer.cpp index 49860008db56..d53008e6e9ee 100644 --- a/src/core/raster/qgsrasterlayer.cpp +++ b/src/core/raster/qgsrasterlayer.cpp @@ -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 @@ -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;