@@ -1133,6 +1133,13 @@ bool QgsGdalProvider::hasHistogram( int theBandNo,
1133
1133
return false ;
1134
1134
}
1135
1135
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
+
1136
1143
QgsDebugMsg ( " Looking for GDAL histogram" );
1137
1144
1138
1145
GDALRasterBandH myGdalBand = GDALGetRasterBand ( mGdalDataset , theBandNo );
@@ -1208,9 +1215,16 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,
1208
1215
}
1209
1216
}
1210
1217
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
+
1211
1225
if ( myHistogram.extent != extent () )
1212
1226
{
1213
- QgsDebugMsg ( " Using generic histogram." );
1227
+ QgsDebugMsg ( " Not full extent, using generic histogram." );
1214
1228
return QgsRasterDataProvider::histogram ( theBandNo, theBinCount, theMinimum, theMaximum, theExtent, theSampleSize, theIncludeOutOfRange );
1215
1229
}
1216
1230
@@ -2035,6 +2049,13 @@ bool QgsGdalProvider::hasStatistics( int theBandNo,
2035
2049
QgsRasterBandStats myRasterBandStats;
2036
2050
initStatistics ( myRasterBandStats, theBandNo, theStats, theExtent, theSampleSize );
2037
2051
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
+
2038
2059
// If not cached, check if supported by GDAL
2039
2060
int supportedStats = QgsRasterBandStats::Min | QgsRasterBandStats::Max
2040
2061
| QgsRasterBandStats::Range | QgsRasterBandStats::Mean
@@ -2120,6 +2141,15 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo, int theStats,
2120
2141
}
2121
2142
}
2122
2143
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
+
2123
2153
int supportedStats = QgsRasterBandStats::Min | QgsRasterBandStats::Max
2124
2154
| QgsRasterBandStats::Range | QgsRasterBandStats::Mean
2125
2155
| QgsRasterBandStats::StdDev;
@@ -2129,7 +2159,7 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo, int theStats,
2129
2159
if ( myRasterBandStats.extent != extent () ||
2130
2160
( theStats & ( ~supportedStats ) ) )
2131
2161
{
2132
- QgsDebugMsg ( " Using generic statistics." );
2162
+ QgsDebugMsg ( " Statistics not supported by provider, using generic statistics." );
2133
2163
return QgsRasterDataProvider::bandStatistics ( theBandNo, theStats, theExtent, theSampleSize );
2134
2164
}
2135
2165
0 commit comments