Skip to content

Commit 8f75b15

Browse files
committed
\#if 0 instead of comment
1 parent d49524c commit 8f75b15

File tree

2 files changed

+67
-62
lines changed

2 files changed

+67
-62
lines changed

src/core/raster/qgsmultibandcolorrenderer.cpp

+43-40
Original file line numberDiff line numberDiff line change
@@ -428,53 +428,56 @@ void QgsMultiBandColorRenderer::toSld( QDomDocument &doc, QDomElement &element,
428428
// create base structure
429429
QgsRasterRenderer::toSld( doc, element, props );
430430

431-
// TODO: the following commented code is necessary to avoid to export channelSelection in
431+
432+
#if 0
433+
// TODO: the following jumped code is necessary to avoid to export channelSelection in
432434
// case it's set as default value. The drawback is that it's necessary to calc band
433435
// statistics that can be really slow depending on dataProvider and rastr localtion.
434436
// this is the reason this part of code is commented and the channelSlection is
435437
// always exported.
436438
//
437439
// before to export check if the band combination and contrast setting are the
438440
// default ones to avoid to export this tags
439-
// bool isDefaultCombination = true;
440-
// QList<int> defaultBandCombination( { 1, 2, 3 } );
441-
442-
// isDefaultCombination = isDefaultCombination && ( usesBands() == defaultBandCombination );
443-
// isDefaultCombination = isDefaultCombination && (
444-
// mRedContrastEnhancement->contrastEnhancementAlgorithm() == QgsContrastEnhancement::StretchToMinimumMaximum &&
445-
// mGreenContrastEnhancement->contrastEnhancementAlgorithm() == QgsContrastEnhancement::StretchToMinimumMaximum &&
446-
// mBlueContrastEnhancement->contrastEnhancementAlgorithm() == QgsContrastEnhancement::StretchToMinimumMaximum
447-
// );
448-
// // compute raster statistics (slow) only if true the previous conditions
449-
// if ( isDefaultCombination)
450-
// {
451-
// QgsRasterBandStats statRed = bandStatistics(1, QgsRasterBandStats::Min|QgsRasterBandStats::Max);
452-
// isDefaultCombination = isDefaultCombination && (
453-
// ( mRedContrastEnhancement->minimumValue() == statRed.minimumValue &&
454-
// mRedContrastEnhancement->maximumValue() == statRed.maximumValue )
455-
// );
456-
// }
457-
// if ( isDefaultCombination)
458-
// {
459-
// QgsRasterBandStats statGreen = bandStatistics(2, QgsRasterBandStats::Min|QgsRasterBandStats::Max);
460-
// isDefaultCombination = isDefaultCombination && (
461-
// ( mGreenContrastEnhancement->minimumValue() == statGreen.minimumValue &&
462-
// mGreenContrastEnhancement->maximumValue() == statGreen.maximumValue )
463-
// );
464-
// }
465-
// if ( isDefaultCombination)
466-
// {
467-
// QgsRasterBandStats statBlue = bandStatistics(3, QgsRasterBandStats::Min|QgsRasterBandStats::Max);
468-
// isDefaultCombination = isDefaultCombination && (
469-
// ( mBlueContrastEnhancement->minimumValue() == statBlue.minimumValue &&
470-
// mBlueContrastEnhancement->maximumValue() == statBlue.maximumValue )
471-
// );
472-
// }
473-
// if ( isDefaultCombination ):
474-
// return
475-
476-
// look for RasterSymbolizer tag
477-
QDomNodeList elements = element.elementsByTagName( QStringLiteral( "sld:RasterSymbolizer" ) );
441+
bool isDefaultCombination = true;
442+
QList<int> defaultBandCombination( { 1, 2, 3 } );
443+
444+
isDefaultCombination = isDefaultCombination && ( usesBands() == defaultBandCombination );
445+
isDefaultCombination = isDefaultCombination && (
446+
mRedContrastEnhancement->contrastEnhancementAlgorithm() == QgsContrastEnhancement::StretchToMinimumMaximum &&
447+
mGreenContrastEnhancement->contrastEnhancementAlgorithm() == QgsContrastEnhancement::StretchToMinimumMaximum &&
448+
mBlueContrastEnhancement->contrastEnhancementAlgorithm() == QgsContrastEnhancement::StretchToMinimumMaximum
449+
);
450+
// compute raster statistics (slow) only if true the previous conditions
451+
if ( isDefaultCombination )
452+
{
453+
QgsRasterBandStats statRed = bandStatistics( 1, QgsRasterBandStats::Min | QgsRasterBandStats::Max );
454+
isDefaultCombination = isDefaultCombination && (
455+
( mRedContrastEnhancement->minimumValue() == statRed.minimumValue &&
456+
mRedContrastEnhancement->maximumValue() == statRed.maximumValue )
457+
);
458+
}
459+
if ( isDefaultCombination )
460+
{
461+
QgsRasterBandStats statGreen = bandStatistics( 2, QgsRasterBandStats::Min | QgsRasterBandStats::Max );
462+
isDefaultCombination = isDefaultCombination && (
463+
( mGreenContrastEnhancement->minimumValue() == statGreen.minimumValue &&
464+
mGreenContrastEnhancement->maximumValue() == statGreen.maximumValue )
465+
);
466+
}
467+
if ( isDefaultCombination )
468+
{
469+
QgsRasterBandStats statBlue = bandStatistics( 3, QgsRasterBandStats::Min | QgsRasterBandStats::Max );
470+
isDefaultCombination = isDefaultCombination && (
471+
( mBlueContrastEnhancement->minimumValue() == statBlue.minimumValue &&
472+
mBlueContrastEnhancement->maximumValue() == statBlue.maximumValue )
473+
);
474+
}
475+
if ( isDefaultCombination ):
476+
return
477+
#endif
478+
479+
// look for RasterSymbolizer tag
480+
QDomNodeList elements = element.elementsByTagName( QStringLiteral( "sld:RasterSymbolizer" ) );
478481
if ( elements.size() == 0 )
479482
return;
480483

src/core/raster/qgsrasterlayer.cpp

+24-22
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,7 @@ bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
13801380
vendorOptionWriter( QStringLiteral( "contrast" ), QString::number( cF ) );
13811381
}
13821382

1383+
#if 0
13831384
// TODO: check if the below mapping formula make sense to map QGIS contrast with SLD gamma value
13841385
//
13851386
// add SLD1.0 ContrastEnhancement GammaValue = QGIS Contrast
@@ -1390,28 +1391,29 @@ bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
13901391
// [-100,0] => [0,1] and [0,100] => [1,100]
13911392
// an alternative could be scale [-100,100] => (0,2]
13921393
//
1393-
// if ( newProps.contains( QStringLiteral( "contrast" ) ) )
1394-
// {
1395-
// double gamma;
1396-
// double contrast = newProps[ QStringLiteral( "contrast" ) ].toDouble();
1397-
// double percentage = (contrast - (-100.0))/(100.0 - (-100.0));
1398-
// if ( percentage <= 0.5)
1399-
// {
1400-
// // stretch % to [0-1]
1401-
// gamma = percentage / 0.5;
1402-
// }
1403-
// else
1404-
// {
1405-
// gamma = contrast;
1406-
// }
1407-
1408-
// QDomElement globalContrastEnhancementElem = doc.createElement( QStringLiteral( "sld:ContrastEnhancement" ) );
1409-
// rasterSymolizerElem.appendChild( globalContrastEnhancementElem );
1410-
1411-
// QDomElement gammaValueElem = doc.createElement( QStringLiteral( "sld:GammaValue" ) );
1412-
// gammaValueElem.appendChild( doc.createTextNode( QString::number( gamma ) ) );
1413-
// globalContrastEnhancementElem.appendChild( gammaValueElem );
1414-
// }
1394+
if ( newProps.contains( QStringLiteral( "contrast" ) ) )
1395+
{
1396+
double gamma;
1397+
double contrast = newProps[ QStringLiteral( "contrast" ) ].toDouble();
1398+
double percentage = ( contrast - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1399+
if ( percentage <= 0.5 )
1400+
{
1401+
// stretch % to [0-1]
1402+
gamma = percentage / 0.5;
1403+
}
1404+
else
1405+
{
1406+
gamma = contrast;
1407+
}
1408+
1409+
QDomElement globalContrastEnhancementElem = doc.createElement( QStringLiteral( "sld:ContrastEnhancement" ) );
1410+
rasterSymolizerElem.appendChild( globalContrastEnhancementElem );
1411+
1412+
QDomElement gammaValueElem = doc.createElement( QStringLiteral( "sld:GammaValue" ) );
1413+
gammaValueElem.appendChild( doc.createTextNode( QString::number( gamma ) ) );
1414+
globalContrastEnhancementElem.appendChild( gammaValueElem );
1415+
}
1416+
#endif
14151417
}
14161418
}
14171419
return true;

0 commit comments

Comments
 (0)