Skip to content

Commit ce7c48f

Browse files
author
ersts
committed
-Fixed problem restoring min max values from project file
-Closes ticket #945 -Added ability choose in the GUI to load estimated or actual min max values from the band -Cleaned and reorganized raster properties gui a little -Added a set default constrast enhancement option in gui that is persistent between sessions -Closes ticket #1055 and #778 git-svn-id: http://svn.osgeo.org/qgis/trunk@8398 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 759fb39 commit ce7c48f

6 files changed

+1195
-733
lines changed

python/core/qgsrasterlayer.sip

+6
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ public:
260260

261261
void setMaximumValue(QString theBand, double theValue, bool theGenerateLookupTableFlag=true);
262262

263+
/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
264+
void computeMinimumMaximumEstimates(int theBand, double* theMinMax);
265+
266+
/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
267+
void computeMinimumMaximumEstimates(QString theBand, double* theMinMax);
268+
263269
QgsContrastEnhancement* getContrastEnhancement(unsigned int theBand);
264270

265271
//

src/app/qgsrasterlayerproperties.cpp

+111-18
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include <QPolygonF>
4343
#include <QColorDialog>
4444
#include <QList>
45-
45+
#include <QSettings>
4646

4747
#include <iostream>
4848

@@ -298,6 +298,7 @@ mRasterLayer( dynamic_cast<QgsRasterLayer*>(lyr) )
298298
pbnDefaultValues->setIcon(QIcon(QPixmap(myThemePath + "/mActionCopySelected.png")));
299299
pbnImportTransparentPixelValues->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileOpen.png")));
300300
pbnExportTransparentPixelValues->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileSave.png")));
301+
pbtnMakeContrastEnhancementAlgorithmDefault->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileSave.png")));
301302

302303
// Only do pyramids if dealing directly with GDAL.
303304
if (mRasterLayerIsGdal)
@@ -613,11 +614,6 @@ void QgsRasterLayerProperties::sync()
613614
cboxInvertColorMap->setChecked(false);
614615
}
615616

616-
//set the transparency slider
617-
sliderTransparency->setValue(255 - mRasterLayer->getTransparency());
618-
//update the transparency percentage label
619-
sliderTransparency_valueChanged(255 - mRasterLayer->getTransparency());
620-
621617
//set the combos to the correct values
622618
cboRed->setCurrentText(mRasterLayer->getRedBandName());
623619
cboGreen->setCurrentText(mRasterLayer->getGreenBandName());
@@ -712,13 +708,45 @@ void QgsRasterLayerProperties::sync()
712708
{
713709
cboxContrastEnhancementAlgorithm->setCurrentText(tr("No Scaling"));
714710
}
711+
712+
//Display the current default contrast enhancement algorithm
713+
QSettings myQSettings;
714+
QString myDefaultAlgorithm = myQSettings.value("/Raster/defaultContrastEnhancementAlgorithm", "NO_STRETCH").toString();
715+
if(myDefaultAlgorithm == "NO_STRETCH")
716+
{
717+
labelDefaultContrastEnhancementAlgorithm->setText(tr("No Scaling"));
718+
}
719+
if(myDefaultAlgorithm == "STRETCH_TO_MINMAX")
720+
{
721+
labelDefaultContrastEnhancementAlgorithm->setText(tr("Stretch To MinMax"));
722+
}
723+
else if(myDefaultAlgorithm == "STRETCH_AND_CLIP_TO_MINMAX")
724+
{
725+
labelDefaultContrastEnhancementAlgorithm->setText(tr("Stretch And Clip To MinMax"));
726+
}
727+
else if(myDefaultAlgorithm == "CLIP_TO_MINMAX")
728+
{
729+
labelDefaultContrastEnhancementAlgorithm->setText(tr("Clip To MinMax"));
730+
}
731+
else
732+
{
733+
labelDefaultContrastEnhancementAlgorithm->setText(tr("No Scaling"));
734+
}
735+
736+
715737

716738
#ifdef QGISDEBUG
717739
QgsDebugMsg("QgsRasterLayerProperties::sync populate transparency tab");
718740
#endif
719741
/*
720742
* Transparent Pixel Tab
721743
*/
744+
745+
//set the transparency slider
746+
sliderTransparency->setValue(255 - mRasterLayer->getTransparency());
747+
//update the transparency percentage label
748+
sliderTransparency_valueChanged(255 - mRasterLayer->getTransparency());
749+
722750
int myIndex = cboxTransparencyLayer->findText(mRasterLayer->getTransparentLayerName());
723751
if(-1 != myIndex)
724752
{
@@ -2697,22 +2725,87 @@ void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
26972725
if(rbtnThreeBand->isChecked())
26982726
{
26992727
rbtnThreeBandMinMax->setChecked(true);
2700-
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboRed->currentText()));
2701-
leRedMin->setText(QString::number(myRasterBandStats.minVal));
2702-
leRedMax->setText(QString::number(myRasterBandStats.maxVal));
2703-
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboGreen->currentText()));
2704-
leGreenMin->setText(QString::number(myRasterBandStats.minVal));
2705-
leGreenMax->setText(QString::number(myRasterBandStats.maxVal));
2706-
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboBlue->currentText()));
2707-
leBlueMin->setText(QString::number(myRasterBandStats.minVal));
2708-
leBlueMax->setText(QString::number(myRasterBandStats.maxVal));
2728+
2729+
if(rbtnActualMinMax->isChecked())
2730+
{
2731+
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboRed->currentText()));
2732+
leRedMin->setText(QString::number(myRasterBandStats.minVal));
2733+
leRedMax->setText(QString::number(myRasterBandStats.maxVal));
2734+
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboGreen->currentText()));
2735+
leGreenMin->setText(QString::number(myRasterBandStats.minVal));
2736+
leGreenMax->setText(QString::number(myRasterBandStats.maxVal));
2737+
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboBlue->currentText()));
2738+
leBlueMin->setText(QString::number(myRasterBandStats.minVal));
2739+
leBlueMax->setText(QString::number(myRasterBandStats.maxVal));
2740+
}
2741+
else
2742+
{
2743+
rbtnEstimateMinMax->setChecked(true);
2744+
double myMinimumMaximum[2];
2745+
mRasterLayer->computeMinimumMaximumEstimates(mRasterLayer->getRasterBandNumber(cboRed->currentText()), myMinimumMaximum);
2746+
leRedMin->setText(QString::number(myMinimumMaximum[0]));
2747+
leRedMax->setText(QString::number(myMinimumMaximum[1]));
2748+
mRasterLayer->computeMinimumMaximumEstimates(mRasterLayer->getRasterBandNumber(cboGreen->currentText()), myMinimumMaximum);
2749+
leGreenMin->setText(QString::number(myMinimumMaximum[0]));
2750+
leGreenMax->setText(QString::number(myMinimumMaximum[1]));
2751+
mRasterLayer->computeMinimumMaximumEstimates(mRasterLayer->getRasterBandNumber(cboBlue->currentText()), myMinimumMaximum);
2752+
leBlueMin->setText(QString::number(myMinimumMaximum[0]));
2753+
leBlueMax->setText(QString::number(myMinimumMaximum[1]));
2754+
}
2755+
27092756
}
27102757
else
27112758
{
27122759
rbtnSingleBandMinMax->setChecked(true);
2713-
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboGray->currentText()));
2714-
leGrayMin->setText(QString::number(myRasterBandStats.minVal));
2715-
leGrayMax->setText(QString::number(myRasterBandStats.maxVal));
2760+
if(rbtnActualMinMax->isChecked())
2761+
{
2762+
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboGray->currentText()));
2763+
leGrayMin->setText(QString::number(myRasterBandStats.minVal));
2764+
leGrayMax->setText(QString::number(myRasterBandStats.maxVal));
2765+
}
2766+
else
2767+
{
2768+
rbtnEstimateMinMax->setChecked(true);
2769+
double myMinimumMaximum[2];
2770+
mRasterLayer->computeMinimumMaximumEstimates(mRasterLayer->getRasterBandNumber(cboGray->currentText()), myMinimumMaximum);
2771+
leGrayMin->setText(QString::number(myMinimumMaximum[0]));
2772+
leGrayMax->setText(QString::number(myMinimumMaximum[1]));
2773+
}
2774+
}
2775+
}
2776+
}
2777+
2778+
void QgsRasterLayerProperties::on_pbtnMakeContrastEnhancementAlgorithmDefault_clicked()
2779+
{
2780+
//Like some of the other functionality in the raster properties GUI this deviated a little from the
2781+
//best practice of GUI design as this pressing cancel will not undo setting the default
2782+
//contrast enhancement algorithm
2783+
if(cboxContrastEnhancementAlgorithm->currentText() != tr("User Defined"))
2784+
{
2785+
QSettings myQSettings;
2786+
if(cboxContrastEnhancementAlgorithm->currentText() == tr("No Stretch"))
2787+
{
2788+
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "NO_STRETCH");
2789+
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
2790+
}
2791+
else if(cboxContrastEnhancementAlgorithm->currentText() == tr("Stretch To MinMax"))
2792+
{
2793+
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "STRETCH_TO_MINMAX");
2794+
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
2795+
}
2796+
else if(cboxContrastEnhancementAlgorithm->currentText() == tr("Stretch And Clip To MinMax"))
2797+
{
2798+
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "STRETCH_AND_CLIP_TO_MINMAX");
2799+
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
2800+
}
2801+
else if(cboxContrastEnhancementAlgorithm->currentText() == tr("Clip To MinMax"))
2802+
{
2803+
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "CLIP_TO_MINMAX");
2804+
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
2805+
}
2806+
else
2807+
{
2808+
//do nothing
27162809
}
27172810
}
27182811
}

src/app/qgsrasterlayerproperties.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
108108
/**Callback for double clicks on the colormap entry widget*/
109109
void handleColormapTreeWidgetDoubleClick(QTreeWidgetItem* item, int column);
110110
/**This slot loads the minimum and maximum values from the raster band and updates the gui*/
111-
void on_pbtnLoadMinMax_clicked();
111+
void on_pbtnLoadMinMax_clicked();
112+
/**This slot save the current contrast enhancement algorithm as the default algorithm */
113+
void on_pbtnMakeContrastEnhancementAlgorithmDefault_clicked();
112114

113115

114116
signals:

src/core/raster/qgsrasterlayer.cpp

+46-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ email : tim at linfiniti.com
6060
#include <QPixmap>
6161
#include <QRegExp>
6262
#include <QSlider>
63-
63+
#include <QSettings>
6464
// workaround for MSVC compiler which already has defined macro max
6565
// that interferes with calling std::numeric_limits<int>::max
6666
#ifdef _MSC_VER
@@ -592,7 +592,9 @@ bool QgsRasterLayer::readFile( QString const & fileName )
592592
}
593593

594594
//defaults - Needs to be set after the Contrast list has been build
595-
setContrastEnhancementAlgorithm(QgsContrastEnhancement::STRETCH_TO_MINMAX);
595+
//Try to read the default contrast enhancement from the config file
596+
QSettings myQSettings;
597+
setContrastEnhancementAlgorithm(myQSettings.value("/Raster/defaultContrastEnhancementAlgorithm", "NO_STRETCH").toString());
596598

597599
//decide what type of layer this is...
598600
//note that multiband images can have one or more 'undefindd' bands,
@@ -4320,6 +4322,16 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )
43204322
myElement = snode.toElement();
43214323
setStdDevsToPlot(myElement.text().toDouble());
43224324

4325+
snode = mnl.namedItem("mUserDefinedRGBMinMaxFlag");
4326+
myElement = snode.toElement();
4327+
myQVariant = (QVariant) myElement.attribute("boolean");
4328+
setUserDefinedRGBMinMax(myQVariant.toBool());
4329+
4330+
snode = mnl.namedItem("mUserDefinedGrayMinMaxFlag");
4331+
myElement = snode.toElement();
4332+
myQVariant = (QVariant) myElement.attribute("boolean");
4333+
setUserDefinedGrayMinMax(myQVariant.toBool());
4334+
43234335
snode = mnl.namedItem("mContrastEnhancementAlgorithm");
43244336
myElement = snode.toElement();
43254337
setContrastEnhancementAlgorithm(myElement.text(), false);
@@ -4659,6 +4671,34 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )
46594671

46604672
rasterPropertiesElement.appendChild( mStandardDeviationsElement );
46614673

4674+
// <mUserDefinedRGBMinMaxFlag>
4675+
QDomElement userDefinedRGBMinMaxFlag = document.createElement( "mUserDefinedRGBMinMaxFlag" );
4676+
4677+
if ( getUserDefinedRGBMinMax() )
4678+
{
4679+
userDefinedRGBMinMaxFlag.setAttribute( "boolean", "true" );
4680+
}
4681+
else
4682+
{
4683+
userDefinedRGBMinMaxFlag.setAttribute( "boolean", "false" );
4684+
}
4685+
4686+
rasterPropertiesElement.appendChild( userDefinedRGBMinMaxFlag );
4687+
4688+
// <mUserDefinedGrayMinMaxFlag>
4689+
QDomElement userDefinedGrayMinMaxFlag = document.createElement( "mUserDefinedGrayMinMaxFlag" );
4690+
4691+
if ( getUserDefinedGrayMinMax() )
4692+
{
4693+
userDefinedGrayMinMaxFlag.setAttribute( "boolean", "true" );
4694+
}
4695+
else
4696+
{
4697+
userDefinedGrayMinMaxFlag.setAttribute( "boolean", "false" );
4698+
}
4699+
4700+
rasterPropertiesElement.appendChild( userDefinedGrayMinMaxFlag );
4701+
46624702
// <contrastEnhancementAlgorithm>
46634703
QDomElement contrastEnhancementAlgorithmElement = document.createElement( "mContrastEnhancementAlgorithm" );
46644704
QDomText contrastEnhancementAlgorithmText = document.createTextNode( getContrastEnhancementAlgorithmAsQString() );
@@ -5391,4 +5431,8 @@ void QgsRasterLayer::setContrastEnhancementAlgorithm(QString theAlgorithm, bool
53915431
{
53925432
setContrastEnhancementAlgorithm(QgsContrastEnhancement::USER_DEFINED, theGenerateLookupTableFlag);
53935433
}
5434+
else
5435+
{
5436+
setContrastEnhancementAlgorithm(QgsContrastEnhancement::NO_STRETCH, theGenerateLookupTableFlag);
5437+
}
53945438
}

src/core/raster/qgsrasterlayer.h

+24
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
463463

464464
// Accessor and mutator for minimum maximum values
465465
//TODO: Move these out of the header file...
466+
/** \brief Accessor for minimum value user for contrast enhancement */
466467
double getMinimumValue(unsigned int theBand)
467468
{
468469
if(0 < theBand && theBand <= getBandCount())
@@ -473,11 +474,13 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
473474
return 0.0;
474475
}
475476

477+
/** \brief Accessor for minimum value user for contrast enhancement */
476478
double getMinimumValue(QString theBand)
477479
{
478480
return getMinimumValue(getRasterBandNumber(theBand));
479481
}
480482

483+
/** \brief Mutator for setting the minimum value for contrast enhancement */
481484
void setMinimumValue(unsigned int theBand, double theValue, bool theGenerateLookupTableFlag=true)
482485
{
483486
if(0 < theBand && theBand <= getBandCount())
@@ -486,6 +489,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
486489
}
487490
}
488491

492+
/** \brief Mutator for setting the minimum value for contrast enhancement */
489493
void setMinimumValue(QString theBand, double theValue, bool theGenerateLookupTableFlag=true)
490494
{
491495
if(theBand != tr("Not Set"))
@@ -495,6 +499,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
495499

496500
}
497501

502+
/** \brief Accessor for maximum value user for contrast enhancement */
498503
double getMaximumValue(unsigned int theBand)
499504
{
500505
if(0 < theBand && theBand <= getBandCount())
@@ -505,6 +510,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
505510
return 0.0;
506511
}
507512

513+
/** \brief Accessor for maximum value user for contrast enhancement */
508514
double getMaximumValue(QString theBand)
509515
{
510516
if(theBand != tr("Not Set"))
@@ -515,6 +521,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
515521
return 0.0;
516522
}
517523

524+
/** \brief Mutator for setting the maximum value for contrast enhancement */
518525
void setMaximumValue(unsigned int theBand, double theValue, bool theGenerateLookupTableFlag=true)
519526
{
520527
if(0 < theBand && theBand <= getBandCount())
@@ -523,6 +530,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
523530
}
524531
}
525532

533+
/** \brief Mutator for setting the maximum value for contrast enhancement */
526534
void setMaximumValue(QString theBand, double theValue, bool theGenerateLookupTableFlag=true)
527535
{
528536
if(theBand != tr("Not Set"))
@@ -531,6 +539,22 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
531539
}
532540
}
533541

542+
/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
543+
void computeMinimumMaximumEstimates(int theBand, double* theMinMax)
544+
{
545+
if(0 < theBand && theBand <= getBandCount())
546+
{
547+
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBand);
548+
GDALComputeRasterMinMax( myGdalBand, 1, theMinMax );
549+
}
550+
}
551+
552+
/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
553+
void computeMinimumMaximumEstimates(QString theBand, double* theMinMax)
554+
{
555+
computeMinimumMaximumEstimates(getRasterBandNumber(theBand), theMinMax);
556+
}
557+
534558
QgsContrastEnhancement* getContrastEnhancement(unsigned int theBand)
535559
{
536560
return &mContrastEnhancementList[theBand - 1];

0 commit comments

Comments
 (0)