Skip to content

Commit 9fb83ca

Browse files
author
ersts
committedNov 8, 2009
-Added ability to load min max values for enhancement based on current portion of the raster being displayed.
-GUI update and string changes. -Closes enhancement ticket 2024 -Accomplished by caching the last QgsRasterViewPort, I see this as a bit of a work around rather than a real solution. The issue at hand is that the render context can only be provided by the map canvas so neither the layer itself nor an layer properties dialog has access to the render context. git-svn-id: http://svn.osgeo.org/qgis/trunk@12015 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5d55476 commit 9fb83ca

File tree

5 files changed

+827
-688
lines changed

5 files changed

+827
-688
lines changed
 

‎python/core/qgsrasterlayer.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ public:
274274
/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
275275
void computeMinimumMaximumEstimates( QString theBand, double* theMinMax );
276276

277+
/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
278+
void computeMinimumMaximumFromLastExtent( int theBand, double* theMinMax );
279+
280+
/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
281+
void computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax );
282+
277283
/** \brief Get a pointer to the contrast enhancement for the selected band */
278284
QgsContrastEnhancement* contrastEnhancement( unsigned int theBand );
279285

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* *
1616
***************************************************************************/
1717

18+
#include <QDebug>
19+
1820
#include "qgslogger.h"
1921
#include "qgsapplication.h"
2022
#include "qgisapp.h"
@@ -434,7 +436,7 @@ void QgsRasterLayerProperties::setMinimumMaximumEstimateWarning()
434436

435437
if ( myEstimatedValues )
436438
{
437-
lblMinMaxEstimateWarning->setText( tr( "Note: Minimum Maximum values are estimates or user defined" ) );
439+
lblMinMaxEstimateWarning->setText( tr( "Note: Minimum Maximum values are estimates, user defined, or calculated from the current extent" ) );
438440
}
439441
else
440442
{
@@ -1934,7 +1936,6 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
19341936
QgsDebugMsg( QString( "max %1" ).arg( myYAxisMax ) );
19351937
QgsDebugMsg( QString( "min %1" ).arg( myYAxisMin ) );
19361938

1937-
19381939
//create the image onto which graph and axes will be drawn
19391940
int myImageWidth = pixHistogram->width() - 2;
19401941
int myImageHeight = pixHistogram->height() - 2; //Take two pixels off to account for the boarder around the QLabel
@@ -2086,6 +2087,7 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
20862087
QgsDebugMsg( QString( "Band %1, bin %2, Hist Value : %3, Scaled Value : %4" ).arg( myIteratorInt ).arg( myBin ).arg( myBinValue ).arg( myY ) );
20872088
QgsDebugMsg( "myY = myGraphImageHeight - myY" );
20882089
QgsDebugMsg( QString( "myY = %1-%2" ).arg( myGraphImageHeight ).arg( myY ) );
2090+
20892091
if ( myGraphType == BAR_CHART )
20902092
{
20912093
//draw the bar
@@ -2136,6 +2138,7 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
21362138
myPolygon << QPointF( myX + myYGutterWidth, myY );
21372139
}
21382140
}
2141+
21392142
if ( myGraphType == LINE_CHART )
21402143
{
21412144
QLinearGradient myGradient;
@@ -2832,6 +2835,9 @@ void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
28322835
if ( mRasterLayerIsGdal && ( mRasterLayer->drawingStyle() == QgsRasterLayer::SingleBandGray || mRasterLayer->drawingStyle() == QgsRasterLayer::MultiBandSingleGandGray || mRasterLayer->drawingStyle() == QgsRasterLayer::MultiBandColor ) )
28332836
{
28342837
QgsRasterBandStats myRasterBandStats;
2838+
double myMinimumMaximum[2];
2839+
myMinimumMaximum[0] = 0;
2840+
myMinimumMaximum[1] = 0;
28352841
if ( rbtnThreeBand->isChecked() )
28362842
{
28372843
rbtnThreeBandMinMax->setChecked( true );
@@ -2849,10 +2855,22 @@ void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
28492855
leBlueMax->setText( QString::number( myRasterBandStats.maximumValue ) );
28502856
mRGBMinimumMaximumEstimated = false;
28512857
}
2858+
else if ( rbtnExtentMinMax->isChecked() )
2859+
{
2860+
mRasterLayer->computeMinimumMaximumFromLastExtent( mRasterLayer->bandNumber( cboRed->currentText() ), myMinimumMaximum );
2861+
leRedMin->setText( QString::number( myMinimumMaximum[0] ) );
2862+
leRedMax->setText( QString::number( myMinimumMaximum[1] ) );
2863+
mRasterLayer->computeMinimumMaximumFromLastExtent( mRasterLayer->bandNumber( cboGreen->currentText() ), myMinimumMaximum );
2864+
leGreenMin->setText( QString::number( myMinimumMaximum[0] ) );
2865+
leGreenMax->setText( QString::number( myMinimumMaximum[1] ) );
2866+
mRasterLayer->computeMinimumMaximumFromLastExtent( mRasterLayer->bandNumber( cboBlue->currentText() ), myMinimumMaximum );
2867+
leBlueMin->setText( QString::number( myMinimumMaximum[0] ) );
2868+
leBlueMax->setText( QString::number( myMinimumMaximum[1] ) );
2869+
mRGBMinimumMaximumEstimated = true;
2870+
}
28522871
else
28532872
{
28542873
rbtnEstimateMinMax->setChecked( true );
2855-
double myMinimumMaximum[2];
28562874
mRasterLayer->computeMinimumMaximumEstimates( mRasterLayer->bandNumber( cboRed->currentText() ), myMinimumMaximum );
28572875
leRedMin->setText( QString::number( myMinimumMaximum[0] ) );
28582876
leRedMax->setText( QString::number( myMinimumMaximum[1] ) );
@@ -2876,10 +2894,16 @@ void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
28762894
leGrayMax->setText( QString::number( myRasterBandStats.maximumValue ) );
28772895
mGrayMinimumMaximumEstimated = false;
28782896
}
2897+
else if ( rbtnExtentMinMax->isChecked() )
2898+
{
2899+
mRasterLayer->computeMinimumMaximumFromLastExtent( mRasterLayer->bandNumber( cboGray->currentText() ), myMinimumMaximum );
2900+
leGrayMin->setText( QString::number( myMinimumMaximum[0] ) );
2901+
leGrayMax->setText( QString::number( myMinimumMaximum[1] ) );
2902+
mGrayMinimumMaximumEstimated = true;
2903+
}
28792904
else
28802905
{
28812906
rbtnEstimateMinMax->setChecked( true );
2882-
double myMinimumMaximum[2];
28832907
mRasterLayer->computeMinimumMaximumEstimates( mRasterLayer->bandNumber( cboGray->currentText() ), myMinimumMaximum );
28842908
leGrayMin->setText( QString::number( myMinimumMaximum[0] ) );
28852909
leGrayMax->setText( QString::number( myMinimumMaximum[1] ) );

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ email : tim at linfiniti.com
1616
***************************************************************************/
1717
/* $Id$ */
1818

19-
2019
#include "qgsapplication.h"
2120
#include "qgslogger.h"
2221
#include "qgsmaplayerregistry.h"
@@ -25,7 +24,6 @@ email : tim at linfiniti.com
2524
#include "qgsrasterbandstats.h"
2625
#include "qgsrasterlayer.h"
2726
#include "qgsrasterpyramid.h"
28-
#include "qgsrasterviewport.h"
2927
#include "qgsrectangle.h"
3028
#include "qgsrendercontext.h"
3129
#include "qgscoordinatereferencesystem.h"
@@ -152,6 +150,20 @@ QgsRasterLayer::QgsRasterLayer(
152150
}
153151
}
154152

153+
//Initialize the last view port structure, should really be a class
154+
mLastViewPort.rectXOffset = 0;
155+
mLastViewPort.rectXOffsetFloat = 0.0;
156+
mLastViewPort.rectYOffset = 0;
157+
mLastViewPort.rectYOffsetFloat = 0.0;
158+
mLastViewPort.clippedXMin = 0.0;
159+
mLastViewPort.clippedXMax = 0.0;
160+
mLastViewPort.clippedYMin = 0.0;
161+
mLastViewPort.clippedYMax = 0.0;
162+
mLastViewPort.clippedWidth = 0;
163+
mLastViewPort.clippedHeight = 0;
164+
mLastViewPort.drawableAreaXDim = 0;
165+
mLastViewPort.drawableAreaYDim = 0;
166+
155167
} // QgsRasterLayer ctor
156168

157169
/**
@@ -1266,6 +1278,52 @@ void QgsRasterLayer::computeMinimumMaximumEstimates( QString theBand, double* th
12661278
computeMinimumMaximumEstimates( bandNumber( theBand ), theMinMax );
12671279
}
12681280

1281+
/**
1282+
* @param theBand The band (number) for which to calculate the min max values
1283+
* @param theMinMax Pointer to a double[2] which hold the estimated min max
1284+
*/
1285+
void QgsRasterLayer::computeMinimumMaximumFromLastExtent( int theBand, double* theMinMax )
1286+
{
1287+
if ( 0 == theMinMax ) { return; }
1288+
1289+
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBand );
1290+
GDALDataType myDataType = GDALGetRasterDataType( myGdalBand );
1291+
void* myGdalScanData = readData( myGdalBand, &mLastViewPort );
1292+
1293+
/* Check for out of memory error */
1294+
if ( myGdalScanData == NULL )
1295+
{
1296+
return;
1297+
}
1298+
1299+
if ( 0 < theBand && theBand <= ( int ) bandCount() )
1300+
{
1301+
float myMin = std::numeric_limits<float>::max();
1302+
float myMax = -1 * std::numeric_limits<float>::max();
1303+
float myValue = 0.0;
1304+
for ( int myRow = 0; myRow < mLastViewPort.drawableAreaYDim; ++myRow )
1305+
{
1306+
for ( int myColumn = 0; myColumn < mLastViewPort.drawableAreaXDim; ++myColumn )
1307+
{
1308+
myValue = readValue( myGdalScanData, myDataType, myRow * mLastViewPort.drawableAreaXDim + myColumn );
1309+
myMin = qMin( myMin, myValue );
1310+
myMax = qMax( myMax, myValue );
1311+
}
1312+
}
1313+
theMinMax[0] = myMin;
1314+
theMinMax[1] = myMax;
1315+
}
1316+
}
1317+
1318+
/**
1319+
* @param theBand The band (name) for which to calculate the min max values
1320+
* @param theMinMax Pointer to a double[2] which hold the estimated min max
1321+
*/
1322+
void QgsRasterLayer::computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax )
1323+
{
1324+
computeMinimumMaximumFromLastExtent( bandNumber( theBand ), theMinMax );
1325+
}
1326+
12691327
/**
12701328
* @param theBand The band (number) for which to get the contrast enhancement for
12711329
* @return Pointer to the contrast enhancement or 0 on failure
@@ -1498,6 +1556,7 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
14981556

14991557
// /\/\/\ - added to handle zoomed-in rasters
15001558

1559+
mLastViewPort = *myRasterViewPort;
15011560

15021561
// Provider mode: See if a provider key is specified, and if so use the provider instead
15031562

‎src/core/raster/qgsrasterlayer.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "qgis.h"
3636
#include "qgspoint.h"
3737
#include "qgsmaplayer.h"
38+
#include "qgsrasterviewport.h"
3839
#include "qgscontrastenhancement.h"
3940
#include "qgsrastertransparency.h"
4041
#include "qgsrastershader.h"
@@ -59,7 +60,6 @@ class QgsRectangle;
5960
class QgsRasterBandStats;
6061
class QgsRasterPyramid;
6162
class QgsRasterLayerProperties;
62-
struct QgsRasterViewPort;
6363
class QImage;
6464
class QPixmap;
6565
class QSlider;
@@ -440,6 +440,12 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
440440
/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
441441
void computeMinimumMaximumEstimates( QString theBand, double* theMinMax );
442442

443+
/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
444+
void computeMinimumMaximumFromLastExtent( int theBand, double* theMinMax );
445+
446+
/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
447+
void computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax );
448+
443449
/** \brief Get a pointer to the contrast enhancement for the selected band */
444450
QgsContrastEnhancement* contrastEnhancement( unsigned int theBand );
445451

@@ -828,6 +834,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
828834
/** [ data provider interface ] Timestamp, the last modified time of the data source when the layer was created */
829835
QDateTime mLastModified;
830836

837+
QgsRasterViewPort mLastViewPort;
838+
831839
/** [ data provider interface ] pointer for loading the provider library */
832840
QLibrary* mLib;
833841

0 commit comments

Comments
 (0)
Please sign in to comment.