Skip to content

Commit

Permalink
Compute min/max on demand in gdal provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Feb 19, 2013
1 parent 2a2465e commit 4d86888
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -787,7 +787,7 @@ double QgsGdalProvider::noDataValue() const
}
#endif

void QgsGdalProvider::computeMinMax( int theBandNo )
void QgsGdalProvider::computeMinMax( int theBandNo ) const
{
QgsDebugMsg( QString( "theBandNo = %1 mMinMaxComputed = %2" ).arg( theBandNo ).arg( mMinMaxComputed[theBandNo-1] ) );
if ( mMinMaxComputed[theBandNo-1] )
Expand All @@ -810,11 +810,22 @@ void QgsGdalProvider::computeMinMax( int theBandNo )
double QgsGdalProvider::minimumValue( int theBandNo ) const
{
QgsDebugMsg( QString( "theBandNo = %1" ).arg( theBandNo ) );
if ( !mMinMaxComputed[theBandNo-1] )
{
computeMinMax( theBandNo );
mMinMaxComputed[theBandNo-1] = true;
}
return mMinimum[theBandNo-1];
}
double QgsGdalProvider::maximumValue( int theBandNo ) const
{
QgsDebugMsg( QString( "theBandNo = %1" ).arg( theBandNo ) );
if ( !mMinMaxComputed[theBandNo-1] )
{
computeMinMax( theBandNo );
mMinMaxComputed[theBandNo-1] = true;
}
computeMinMax( theBandNo );
return mMaximum[theBandNo-1];
}

Expand Down Expand Up @@ -2341,7 +2352,6 @@ void QgsGdalProvider::initBaseDataset()
//mValidNoDataValue = true;
for ( int i = 1; i <= GDALGetRasterCount( mGdalBaseDataset ); i++ )
{
computeMinMax( i );
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, i );
GDALDataType myGdalDataType = GDALGetRasterDataType( myGdalBand );

Expand Down
8 changes: 4 additions & 4 deletions src/providers/gdal/qgsgdalprovider.h
Expand Up @@ -179,7 +179,7 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase

//bool srcHasNoDataValue( int bandNo ) const;
//double noDataValue() const;
void computeMinMax( int bandNo );
void computeMinMax( int bandNo ) const;
double minimumValue( int bandNo ) const;
double maximumValue( int bandNo ) const;

Expand Down Expand Up @@ -294,13 +294,13 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
int mXBlockSize;
int mYBlockSize;

QList<bool> mMinMaxComputed;
mutable QList<bool> mMinMaxComputed;

// List of estimated min values, index 0 for band 1
QList<double> mMinimum;
mutable QList<double> mMinimum;

// List of estimated max values, index 0 for band 1
QList<double> mMaximum;
mutable QList<double> mMaximum;

/** \brief Pointer to the gdaldataset */
GDALDatasetH mGdalBaseDataset;
Expand Down

0 comments on commit 4d86888

Please sign in to comment.