QGIS API Documentation  2.4.0-Chugiak
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsrasterminmaxwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterminmaxwidget.h
3  ---------------------------------
4  begin : July 2012
5  copyright : (C) 2012 by Radim Blazek
6  email : radim dot blazek at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include <QSettings>
19 #include <QMessageBox>
20 
21 #include "qgsrasterlayer.h"
22 #include "qgsrasterminmaxwidget.h"
23 
25  QWidget( parent )
26  , mLayer( theLayer )
27 {
28  QgsDebugMsg( "Entered." );
29  setupUi( this );
30 
31  QSettings mySettings;
32 
33  // set contrast enhancement setting to default
34  // ideally we should set it actual method last used to get min/max, but there is no way to know currently
35  QString contrastEnchacementLimits = mySettings.value( "/Raster/defaultContrastEnhancementLimits", "CumulativeCut" ).toString();
36  if ( contrastEnchacementLimits == "MinMax" )
37  mMinMaxRadioButton->setChecked( true );
38  else if ( contrastEnchacementLimits == "StdDev" )
39  mStdDevRadioButton->setChecked( true );
40 
41  double myLower = 100.0 * mySettings.value( "/Raster/cumulativeCutLower", QString::number( QgsRasterLayer::CUMULATIVE_CUT_LOWER ) ).toDouble();
42  double myUpper = 100.0 * mySettings.value( "/Raster/cumulativeCutUpper", QString::number( QgsRasterLayer::CUMULATIVE_CUT_UPPER ) ).toDouble();
43  mCumulativeCutLowerDoubleSpinBox->setValue( myLower );
44  mCumulativeCutUpperDoubleSpinBox->setValue( myUpper );
45 
46  mStdDevSpinBox->setValue( mySettings.value( "/Raster/defaultStandardDeviation", 2.0 ).toDouble() );
47 }
48 
50 {
51 }
52 
54 {
55  QgsDebugMsg( "Entered." );
56 
57  foreach ( int myBand, mBands )
58  {
60  QgsDebugMsg( QString( "myBand = %1" ).arg( myBand ) );
61  if ( myBand < 1 || myBand > mLayer->dataProvider()->bandCount() )
62  {
63  continue;
64  }
65  double myMin = std::numeric_limits<double>::quiet_NaN();
66  double myMax = std::numeric_limits<double>::quiet_NaN();
67 
68  QgsRectangle myExtent; // empty == full
69  if ( mCurrentExtentRadioButton->isChecked() )
70  {
71  myExtent = mExtent; // current
73  }
74  else
75  {
77  }
78  QgsDebugMsg( QString( "myExtent.isEmpty() = %1" ).arg( myExtent.isEmpty() ) );
79 
80  int mySampleSize = 0; // 0 == exact
81  if ( mEstimateRadioButton->isChecked() )
82  {
83  mySampleSize = 250000;
85  }
86  else
87  {
89  }
90 
91  if ( mCumulativeCutRadioButton->isChecked() )
92  {
93  double myLower = mCumulativeCutLowerDoubleSpinBox->value() / 100.0;
94  double myUpper = mCumulativeCutUpperDoubleSpinBox->value() / 100.0;
95  mLayer->dataProvider()->cumulativeCut( myBand, myLower, myUpper, myMin, myMax, myExtent, mySampleSize );
97  }
98  else if ( mMinMaxRadioButton->isChecked() )
99  {
100  // TODO: consider provider minimum/maximumValue() (has to be defined well in povider)
101  QgsRasterBandStats myRasterBandStats = mLayer->dataProvider()->bandStatistics( myBand, QgsRasterBandStats::Min | QgsRasterBandStats::Max, myExtent, mySampleSize );
102  myMin = myRasterBandStats.minimumValue;
103  myMax = myRasterBandStats.maximumValue;
105  }
106  else if ( mStdDevRadioButton->isChecked() )
107  {
108  QgsRasterBandStats myRasterBandStats = mLayer->dataProvider()->bandStatistics( myBand, QgsRasterBandStats::Mean | QgsRasterBandStats::StdDev, myExtent, mySampleSize );
109  double myStdDev = mStdDevSpinBox->value();
110  myMin = myRasterBandStats.mean - ( myStdDev * myRasterBandStats.stdDev );
111  myMax = myRasterBandStats.mean + ( myStdDev * myRasterBandStats.stdDev );
113  }
114  else
115  {
116  QMessageBox::warning( this, tr( "No option selected" ), tr( "Please select an option to load min/max values." ) );
117  return;
118  }
119 
120  emit load( myBand, myMin, myMax, origin );
121  }
122 }
virtual int bandCount() const =0
Get number of bands.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
bool isEmpty() const
test if rectangle is empty.
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
double maximumValue
The maximum cell value in the raster band.
virtual QgsRasterBandStats bandStatistics(int theBandNo, int theStats=QgsRasterBandStats::All, const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0)
Get band statistics.
double stdDev
The standard deviation of the cell values.
The RasterBandStats struct is a container for statistics about a single raster band.
double mean
The mean cell value for the band.
static const double CUMULATIVE_CUT_UPPER
Default cumulative cut upper limit.
static const double CUMULATIVE_CUT_LOWER
Default cumulative cut lower limit.
QgsRasterMinMaxWidget(QgsRasterLayer *theLayer, QWidget *parent=0)
double minimumValue
The minimum cell value in the raster band.
QgsRasterDataProvider * dataProvider()
Returns the data provider.
virtual void cumulativeCut(int theBandNo, double theLowerCount, double theUpperCount, double &theLowerValue, double &theUpperValue, const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0)
Find values for cumulative pixel count cut.
#define tr(sourceText)