Skip to content

Commit b4d206a

Browse files
committed
Updates for GDAL 2
1 parent ec1097c commit b4d206a

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,13 +1278,21 @@ bool QgsGdalProvider::hasHistogram( int theBandNo,
12781278
// get default histogram with force=false to see if there is a cached histo
12791279
double myMinVal, myMaxVal;
12801280
int myBinCount;
1281-
int *myHistogramArray = 0;
1281+
1282+
#if GDAL_VERSION_MAJOR >= 2
1283+
GUIntBig* myHistogramArray = 0;
1284+
CPLErr myError = GDALGetDefaultHistogramEx( myGdalBand, &myMinVal, &myMaxVal,
1285+
&myBinCount, &myHistogramArray, false,
1286+
NULL, NULL );
1287+
#else
1288+
int* myHistogramArray = 0;
12821289

12831290
// TODO: GDALGetDefaultHistogram has no bIncludeOutOfRange and bApproxOK,
12841291
// consider consequences
12851292
CPLErr myError = GDALGetDefaultHistogram( myGdalBand, &myMinVal, &myMaxVal,
12861293
&myBinCount, &myHistogramArray, false,
12871294
NULL, NULL );
1295+
#endif
12881296

12891297
if ( myHistogramArray )
12901298
VSIFree( myHistogramArray ); // use VSIFree because allocated by GDAL
@@ -1433,11 +1441,20 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,
14331441
}
14341442
#endif
14351443

1436-
int *myHistogramArray = new int[myHistogram.binCount];
1444+
#if GDAL_VERSION_MAJOR >= 2
1445+
GUIntBig* myHistogramArray = new GUIntBig[myHistogram.binCount];
1446+
CPLErr myError = GDALGetRasterHistogramEx( myGdalBand, myMinVal, myMaxVal,
1447+
myHistogram.binCount, myHistogramArray,
1448+
theIncludeOutOfRange, bApproxOK, progressCallback,
1449+
&myProg ); //this is the arg for our custom gdal progress callback
1450+
#else
1451+
int* myHistogramArray = new int[myHistogram.binCount];
14371452
CPLErr myError = GDALGetRasterHistogram( myGdalBand, myMinVal, myMaxVal,
14381453
myHistogram.binCount, myHistogramArray,
14391454
theIncludeOutOfRange, bApproxOK, progressCallback,
14401455
&myProg ); //this is the arg for our custom gdal progress callback
1456+
#endif
1457+
14411458
if ( myError != CE_None )
14421459
{
14431460
QgsDebugMsg( "Cannot get histogram" );
@@ -1449,12 +1466,14 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,
14491466

14501467
for ( int myBin = 0; myBin < myHistogram.binCount; myBin++ )
14511468
{
1469+
#if GDAL_VERSION_MAJOR < 2
14521470
if ( myHistogramArray[myBin] < 0 ) //can't have less than 0 pixels of any value
14531471
{
14541472
myHistogram.histogramVector.push_back( 0 );
14551473
// QgsDebugMsg( "Added 0 to histogram vector as freq was negative!" );
14561474
}
14571475
else
1476+
#endif
14581477
{
14591478
myHistogram.histogramVector.push_back( myHistogramArray[myBin] );
14601479
myHistogram.nonNullCount += myHistogramArray[myBin];

0 commit comments

Comments
 (0)