QGIS API Documentation  2.0.1-Dufour
 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 
20 #include "qgsrasterlayer.h"
21 #include "qgsrasterminmaxwidget.h"
22 
24  QWidget( parent )
25  , mLayer( theLayer )
26 {
27  QgsDebugMsg( "Entered." );
28  setupUi( this );
29 
30  QSettings mySettings;
31  double myLower = 100.0 * mySettings.value( "/Raster/cumulativeCutLower", QString::number( QgsRasterLayer::CUMULATIVE_CUT_LOWER ) ).toDouble();
32  double myUpper = 100.0 * mySettings.value( "/Raster/cumulativeCutUpper", QString::number( QgsRasterLayer::CUMULATIVE_CUT_UPPER ) ).toDouble();
33  mCumulativeCutLowerDoubleSpinBox->setValue( myLower );
34  mCumulativeCutUpperDoubleSpinBox->setValue( myUpper );
35 }
36 
38 {
39 }
40 
42 {
43  QgsDebugMsg( "Entered." );
44 
45  foreach ( int myBand, mBands )
46  {
48  QgsDebugMsg( QString( "myBand = %1" ).arg( myBand ) );
49  if ( myBand < 1 || myBand > mLayer->dataProvider()->bandCount() )
50  {
51  continue;
52  }
53  double myMin = std::numeric_limits<double>::quiet_NaN();
54  double myMax = std::numeric_limits<double>::quiet_NaN();
55 
56  QgsRectangle myExtent; // empty == full
57  if ( mCurrentExtentRadioButton->isChecked() )
58  {
59  myExtent = mExtent; // current
61  }
62  else
63  {
65  }
66  QgsDebugMsg( QString( "myExtent.isEmpty() = %1" ).arg( myExtent.isEmpty() ) );
67 
68  int mySampleSize = 0; // 0 == exact
69  if ( mEstimateRadioButton->isChecked() )
70  {
71  mySampleSize = 250000;
73  }
74  else
75  {
77  }
78 
79  if ( mCumulativeCutRadioButton->isChecked() )
80  {
81  double myLower = mCumulativeCutLowerDoubleSpinBox->value() / 100.0;
82  double myUpper = mCumulativeCutUpperDoubleSpinBox->value() / 100.0;
83  mLayer->dataProvider()->cumulativeCut( myBand, myLower, myUpper, myMin, myMax, myExtent, mySampleSize );
85  }
86  else if ( mMinMaxRadioButton->isChecked() )
87  {
88  // TODO: consider provider minimum/maximumValue() (has to be defined well in povider)
89  QgsRasterBandStats myRasterBandStats = mLayer->dataProvider()->bandStatistics( myBand, QgsRasterBandStats::Min | QgsRasterBandStats::Max, myExtent, mySampleSize );
90  myMin = myRasterBandStats.minimumValue;
91  myMax = myRasterBandStats.maximumValue;
93  }
94  else if ( mStdDevRadioButton->isChecked() )
95  {
96  QgsRasterBandStats myRasterBandStats = mLayer->dataProvider()->bandStatistics( myBand, QgsRasterBandStats::Mean | QgsRasterBandStats::StdDev, myExtent, mySampleSize );
97  double myStdDev = mStdDevSpinBox->value();
98  myMin = myRasterBandStats.mean - ( myStdDev * myRasterBandStats.stdDev );
99  myMax = myRasterBandStats.mean + ( myStdDev * myRasterBandStats.stdDev );
101  }
102 
103  emit load( myBand, myMin, myMax, origin );
104  }
105 }