Skip to content
Permalink
Browse files

\#if 0 instead of comment

  • Loading branch information
luipir committed Feb 1, 2019
1 parent d49524c commit 8f75b1592821df329713fd8f7891214805e49173
Showing with 67 additions and 62 deletions.
  1. +43 −40 src/core/raster/qgsmultibandcolorrenderer.cpp
  2. +24 −22 src/core/raster/qgsrasterlayer.cpp
@@ -428,53 +428,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;

@@ -1380,6 +1380,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
@@ -1390,28 +1391,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;

0 comments on commit 8f75b15

Please sign in to comment.
You can’t perform that action at this time.