Skip to content

Commit 738ec79

Browse files
committedFeb 1, 2019
\#if 0 instead of comment
1 parent 461b31d commit 738ec79

File tree

2 files changed

+67
-62
lines changed

2 files changed

+67
-62
lines changed
 

‎src/core/raster/qgsmultibandcolorrenderer.cpp

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -425,53 +425,56 @@ void QgsMultiBandColorRenderer::toSld( QDomDocument &doc, QDomElement &element,
425425
// create base structure
426426
QgsRasterRenderer::toSld( doc, element, props );
427427

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

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,7 @@ bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
14441444
vendorOptionWriter( QStringLiteral( "contrast" ), QString::number( cF ) );
14451445
}
14461446

1447+
#if 0
14471448
// TODO: check if the below mapping formula make sense to map QGIS contrast with SLD gamma value
14481449
//
14491450
// add SLD1.0 ContrastEnhancement GammaValue = QGIS Contrast
@@ -1454,28 +1455,29 @@ bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
14541455
// [-100,0] => [0,1] and [0,100] => [1,100]
14551456
// an alternative could be scale [-100,100] => (0,2]
14561457
//
1457-
// if ( newProps.contains( QStringLiteral( "contrast" ) ) )
1458-
// {
1459-
// double gamma;
1460-
// double contrast = newProps[ QStringLiteral( "contrast" ) ].toDouble();
1461-
// double percentage = (contrast - (-100.0))/(100.0 - (-100.0));
1462-
// if ( percentage <= 0.5)
1463-
// {
1464-
// // stretch % to [0-1]
1465-
// gamma = percentage / 0.5;
1466-
// }
1467-
// else
1468-
// {
1469-
// gamma = contrast;
1470-
// }
1471-
1472-
// QDomElement globalContrastEnhancementElem = doc.createElement( QStringLiteral( "sld:ContrastEnhancement" ) );
1473-
// rasterSymolizerElem.appendChild( globalContrastEnhancementElem );
1474-
1475-
// QDomElement gammaValueElem = doc.createElement( QStringLiteral( "sld:GammaValue" ) );
1476-
// gammaValueElem.appendChild( doc.createTextNode( QString::number( gamma ) ) );
1477-
// globalContrastEnhancementElem.appendChild( gammaValueElem );
1478-
// }
1458+
if ( newProps.contains( QStringLiteral( "contrast" ) ) )
1459+
{
1460+
double gamma;
1461+
double contrast = newProps[ QStringLiteral( "contrast" ) ].toDouble();
1462+
double percentage = ( contrast - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1463+
if ( percentage <= 0.5 )
1464+
{
1465+
// stretch % to [0-1]
1466+
gamma = percentage / 0.5;
1467+
}
1468+
else
1469+
{
1470+
gamma = contrast;
1471+
}
1472+
1473+
QDomElement globalContrastEnhancementElem = doc.createElement( QStringLiteral( "sld:ContrastEnhancement" ) );
1474+
rasterSymolizerElem.appendChild( globalContrastEnhancementElem );
1475+
1476+
QDomElement gammaValueElem = doc.createElement( QStringLiteral( "sld:GammaValue" ) );
1477+
gammaValueElem.appendChild( doc.createTextNode( QString::number( gamma ) ) );
1478+
globalContrastEnhancementElem.appendChild( gammaValueElem );
1479+
}
1480+
#endif
14791481
}
14801482
}
14811483
return true;

0 commit comments

Comments
 (0)
Please sign in to comment.