Skip to content

Commit

Permalink
Set gathered statistics to none when there are no statistics
Browse files Browse the repository at this point in the history
Fixes #41662

(cherry picked from commit caa1917)
  • Loading branch information
elpaso authored and nyalldawson committed Mar 19, 2021
1 parent 03d20e0 commit 972afd3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/core/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -2863,6 +2863,10 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int bandNo, int stats, const
QgsDebugMsgLevel( QStringLiteral( "STDDEV %1" ).arg( myRasterBandStats.stdDev ), 2 );
#endif
}
else
{
myRasterBandStats.statsGathered = QgsRasterBandStats::Stats::None;
}

mStatistics.append( myRasterBandStats );
return myRasterBandStats;
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -982,8 +982,8 @@ void QgsRasterLayer::computeMinMax( int band,
if ( limits == QgsRasterMinMaxOrigin::MinMax )
{
QgsRasterBandStats myRasterBandStats = mDataProvider->bandStatistics( band, QgsRasterBandStats::Min | QgsRasterBandStats::Max, extent, sampleSize );
// Check if statistics were actually gathered, 0 means a failure
if ( myRasterBandStats.elementCount == 0 )
// Check if statistics were actually gathered, None means a failure
if ( myRasterBandStats.statsGathered == QgsRasterBandStats::Stats::None )
{
// Best guess we can do
switch ( mDataProvider->dataType( band ) )
Expand Down

0 comments on commit 972afd3

Please sign in to comment.