@@ -1133,6 +1133,13 @@ bool QgsGdalProvider::hasHistogram( int theBandNo,
11331133 return false ;
11341134 }
11351135
1136+ if (( srcHasNoDataValue ( theBandNo ) && !useSrcNoDataValue ( theBandNo ) ) ||
1137+ userNoDataValue ( theBandNo ).size () > 0 )
1138+ {
1139+ QgsDebugMsg ( " Custom no data values -> GDAL histogram not sufficient." );
1140+ return false ;
1141+ }
1142+
11361143 QgsDebugMsg ( " Looking for GDAL histogram" );
11371144
11381145 GDALRasterBandH myGdalBand = GDALGetRasterBand ( mGdalDataset , theBandNo );
@@ -1208,9 +1215,16 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,
12081215 }
12091216 }
12101217
1218+ if (( srcHasNoDataValue ( theBandNo ) && !useSrcNoDataValue ( theBandNo ) ) ||
1219+ userNoDataValue ( theBandNo ).size () > 0 )
1220+ {
1221+ QgsDebugMsg ( " Custom no data values, using generic histogram." );
1222+ return QgsRasterDataProvider::histogram ( theBandNo, theBinCount, theMinimum, theMaximum, theExtent, theSampleSize, theIncludeOutOfRange );
1223+ }
1224+
12111225 if ( myHistogram.extent != extent () )
12121226 {
1213- QgsDebugMsg ( " Using generic histogram." );
1227+ QgsDebugMsg ( " Not full extent, using generic histogram." );
12141228 return QgsRasterDataProvider::histogram ( theBandNo, theBinCount, theMinimum, theMaximum, theExtent, theSampleSize, theIncludeOutOfRange );
12151229 }
12161230
@@ -2035,6 +2049,13 @@ bool QgsGdalProvider::hasStatistics( int theBandNo,
20352049 QgsRasterBandStats myRasterBandStats;
20362050 initStatistics ( myRasterBandStats, theBandNo, theStats, theExtent, theSampleSize );
20372051
2052+ if (( srcHasNoDataValue ( theBandNo ) && !useSrcNoDataValue ( theBandNo ) ) ||
2053+ userNoDataValue ( theBandNo ).size () > 0 )
2054+ {
2055+ QgsDebugMsg ( " Custom no data values -> GDAL statistics not sufficient." );
2056+ return false ;
2057+ }
2058+
20382059 // If not cached, check if supported by GDAL
20392060 int supportedStats = QgsRasterBandStats::Min | QgsRasterBandStats::Max
20402061 | QgsRasterBandStats::Range | QgsRasterBandStats::Mean
@@ -2120,6 +2141,15 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo, int theStats,
21202141 }
21212142 }
21222143
2144+ // We cannot use GDAL stats if user disabled src no data value or set
2145+ // custom no data values
2146+ if (( srcHasNoDataValue ( theBandNo ) && !useSrcNoDataValue ( theBandNo ) ) ||
2147+ userNoDataValue ( theBandNo ).size () > 0 )
2148+ {
2149+ QgsDebugMsg ( " Custom no data values, using generic statistics." );
2150+ return QgsRasterDataProvider::bandStatistics ( theBandNo, theStats, theExtent, theSampleSize );
2151+ }
2152+
21232153 int supportedStats = QgsRasterBandStats::Min | QgsRasterBandStats::Max
21242154 | QgsRasterBandStats::Range | QgsRasterBandStats::Mean
21252155 | QgsRasterBandStats::StdDev;
@@ -2129,7 +2159,7 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo, int theStats,
21292159 if ( myRasterBandStats.extent != extent () ||
21302160 ( theStats & ( ~supportedStats ) ) )
21312161 {
2132- QgsDebugMsg ( " Using generic statistics." );
2162+ QgsDebugMsg ( " Statistics not supported by provider, using generic statistics." );
21332163 return QgsRasterDataProvider::bandStatistics ( theBandNo, theStats, theExtent, theSampleSize );
21342164 }
21352165
0 commit comments