@@ -1278,13 +1278,21 @@ bool QgsGdalProvider::hasHistogram( int theBandNo,
1278
1278
// get default histogram with force=false to see if there is a cached histo
1279
1279
double myMinVal, myMaxVal;
1280
1280
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 ;
1282
1289
1283
1290
// TODO: GDALGetDefaultHistogram has no bIncludeOutOfRange and bApproxOK,
1284
1291
// consider consequences
1285
1292
CPLErr myError = GDALGetDefaultHistogram ( myGdalBand, &myMinVal, &myMaxVal,
1286
1293
&myBinCount, &myHistogramArray, false ,
1287
1294
NULL , NULL );
1295
+ #endif
1288
1296
1289
1297
if ( myHistogramArray )
1290
1298
VSIFree ( myHistogramArray ); // use VSIFree because allocated by GDAL
@@ -1433,11 +1441,20 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,
1433
1441
}
1434
1442
#endif
1435
1443
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 ];
1437
1452
CPLErr myError = GDALGetRasterHistogram ( myGdalBand, myMinVal, myMaxVal,
1438
1453
myHistogram.binCount , myHistogramArray,
1439
1454
theIncludeOutOfRange, bApproxOK, progressCallback,
1440
1455
&myProg ); // this is the arg for our custom gdal progress callback
1456
+ #endif
1457
+
1441
1458
if ( myError != CE_None )
1442
1459
{
1443
1460
QgsDebugMsg ( " Cannot get histogram" );
@@ -1449,12 +1466,14 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,
1449
1466
1450
1467
for ( int myBin = 0 ; myBin < myHistogram.binCount ; myBin++ )
1451
1468
{
1469
+ #if GDAL_VERSION_MAJOR < 2
1452
1470
if ( myHistogramArray[myBin] < 0 ) // can't have less than 0 pixels of any value
1453
1471
{
1454
1472
myHistogram.histogramVector .push_back ( 0 );
1455
1473
// QgsDebugMsg( "Added 0 to histogram vector as freq was negative!" );
1456
1474
}
1457
1475
else
1476
+ #endif
1458
1477
{
1459
1478
myHistogram.histogramVector .push_back ( myHistogramArray[myBin] );
1460
1479
myHistogram.nonNullCount += myHistogramArray[myBin];
0 commit comments