Skip to content

Commit

Permalink
Updates for GDAL 2
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 11, 2015
1 parent ec1097c commit b4d206a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1278,13 +1278,21 @@ bool QgsGdalProvider::hasHistogram( int theBandNo,
// get default histogram with force=false to see if there is a cached histo
double myMinVal, myMaxVal;
int myBinCount;
int *myHistogramArray = 0;

#if GDAL_VERSION_MAJOR >= 2
GUIntBig* myHistogramArray = 0;
CPLErr myError = GDALGetDefaultHistogramEx( myGdalBand, &myMinVal, &myMaxVal,
&myBinCount, &myHistogramArray, false,
NULL, NULL );
#else
int* myHistogramArray = 0;

// TODO: GDALGetDefaultHistogram has no bIncludeOutOfRange and bApproxOK,
// consider consequences
CPLErr myError = GDALGetDefaultHistogram( myGdalBand, &myMinVal, &myMaxVal,
&myBinCount, &myHistogramArray, false,
NULL, NULL );
#endif

if ( myHistogramArray )
VSIFree( myHistogramArray ); // use VSIFree because allocated by GDAL
Expand Down Expand Up @@ -1433,11 +1441,20 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,
}
#endif

int *myHistogramArray = new int[myHistogram.binCount];
#if GDAL_VERSION_MAJOR >= 2
GUIntBig* myHistogramArray = new GUIntBig[myHistogram.binCount];
CPLErr myError = GDALGetRasterHistogramEx( myGdalBand, myMinVal, myMaxVal,
myHistogram.binCount, myHistogramArray,
theIncludeOutOfRange, bApproxOK, progressCallback,
&myProg ); //this is the arg for our custom gdal progress callback
#else
int* myHistogramArray = new int[myHistogram.binCount];
CPLErr myError = GDALGetRasterHistogram( myGdalBand, myMinVal, myMaxVal,
myHistogram.binCount, myHistogramArray,
theIncludeOutOfRange, bApproxOK, progressCallback,
&myProg ); //this is the arg for our custom gdal progress callback
#endif

if ( myError != CE_None )
{
QgsDebugMsg( "Cannot get histogram" );
Expand All @@ -1449,12 +1466,14 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,

for ( int myBin = 0; myBin < myHistogram.binCount; myBin++ )
{
#if GDAL_VERSION_MAJOR < 2
if ( myHistogramArray[myBin] < 0 ) //can't have less than 0 pixels of any value
{
myHistogram.histogramVector.push_back( 0 );
// QgsDebugMsg( "Added 0 to histogram vector as freq was negative!" );
}
else
#endif
{
myHistogram.histogramVector.push_back( myHistogramArray[myBin] );
myHistogram.nonNullCount += myHistogramArray[myBin];
Expand Down

0 comments on commit b4d206a

Please sign in to comment.