QGIS API Documentation  master-6227475
src/gui/raster/qgsrasterminmaxwidget.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                          qgsrasterminmaxwidget.h
00003                          ---------------------------------
00004     begin                : July 2012
00005     copyright            : (C) 2012 by Radim Blazek
00006     email                : radim dot blazek at gmail dot com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <QSettings>
00019 
00020 #include "qgsrasterlayer.h"
00021 #include "qgsrasterminmaxwidget.h"
00022 
00023 QgsRasterMinMaxWidget::QgsRasterMinMaxWidget( QgsRasterLayer* theLayer, QWidget *parent ):
00024     QWidget( parent )
00025     , mLayer( theLayer )
00026 {
00027   QgsDebugMsg( "Entered." );
00028   setupUi( this );
00029 
00030   QSettings mySettings;
00031   double myLower = 100.0 * mySettings.value( "/Raster/cumulativeCutLower", QString::number( QgsRasterLayer::CUMULATIVE_CUT_LOWER ) ).toDouble();
00032   double myUpper = 100.0 * mySettings.value( "/Raster/cumulativeCutUpper", QString::number( QgsRasterLayer::CUMULATIVE_CUT_UPPER ) ).toDouble();
00033   mCumulativeCutLowerDoubleSpinBox->setValue( myLower );
00034   mCumulativeCutUpperDoubleSpinBox->setValue( myUpper );
00035 }
00036 
00037 QgsRasterMinMaxWidget::~QgsRasterMinMaxWidget()
00038 {
00039 }
00040 
00041 void QgsRasterMinMaxWidget::on_mLoadPushButton_clicked()
00042 {
00043   QgsDebugMsg( "Entered." );
00044 
00045   foreach ( int myBand, mBands )
00046   {
00047     int origin = QgsRasterRenderer::MinMaxUnknown;
00048     QgsDebugMsg( QString( "myBand = %1" ).arg( myBand ) );
00049     if ( myBand < 1 || myBand > mLayer->dataProvider()->bandCount() )
00050     {
00051       continue;
00052     }
00053     double myMin = std::numeric_limits<double>::quiet_NaN();
00054     double myMax = std::numeric_limits<double>::quiet_NaN();
00055 
00056     QgsRectangle myExtent; // empty == full
00057     if ( mCurrentExtentRadioButton->isChecked() )
00058     {
00059       myExtent = mExtent; // current
00060       origin |= QgsRasterRenderer::MinMaxSubExtent;
00061     }
00062     else
00063     {
00064       origin |= QgsRasterRenderer::MinMaxFullExtent;
00065     }
00066     QgsDebugMsg( QString( "myExtent.isEmpty() = %1" ).arg( myExtent.isEmpty() ) );
00067 
00068     int mySampleSize = 0; // 0 == exact
00069     if ( mEstimateRadioButton->isChecked() )
00070     {
00071       mySampleSize = 250000;
00072       origin |= QgsRasterRenderer::MinMaxEstimated;
00073     }
00074     else
00075     {
00076       origin |= QgsRasterRenderer::MinMaxExact;
00077     }
00078 
00079     if ( mCumulativeCutRadioButton->isChecked() )
00080     {
00081       double myLower = mCumulativeCutLowerDoubleSpinBox->value() / 100.0;
00082       double myUpper = mCumulativeCutUpperDoubleSpinBox->value() / 100.0;
00083       mLayer->dataProvider()->cumulativeCut( myBand, myLower, myUpper, myMin, myMax, myExtent, mySampleSize );
00084       origin |= QgsRasterRenderer::MinMaxCumulativeCut;
00085     }
00086     else if ( mMinMaxRadioButton->isChecked() )
00087     {
00088       // TODO: consider provider minimum/maximumValue() (has to be defined well in povider)
00089       QgsRasterBandStats myRasterBandStats = mLayer->dataProvider()->bandStatistics( myBand, QgsRasterBandStats::Min | QgsRasterBandStats::Max, myExtent, mySampleSize );
00090       myMin = myRasterBandStats.minimumValue;
00091       myMax = myRasterBandStats.maximumValue;
00092       origin |= QgsRasterRenderer::MinMaxMinMax;
00093     }
00094     else if ( mStdDevRadioButton->isChecked() )
00095     {
00096       QgsRasterBandStats myRasterBandStats = mLayer->dataProvider()->bandStatistics( myBand, QgsRasterBandStats::Mean | QgsRasterBandStats::StdDev, myExtent, mySampleSize );
00097       double myStdDev = mStdDevSpinBox->value();
00098       myMin = myRasterBandStats.mean - ( myStdDev * myRasterBandStats.stdDev );
00099       myMax = myRasterBandStats.mean + ( myStdDev * myRasterBandStats.stdDev );
00100       origin |= QgsRasterRenderer::MinMaxStdDev;
00101     }
00102 
00103     emit load( myBand, myMin, myMax, origin );
00104   }
00105 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines