Skip to content
Permalink
Browse files
Fix unreported missing raster band stats in info panel
  • Loading branch information
elpaso authored and nyalldawson committed Jun 2, 2021
1 parent c1c068b commit 49265a8c8514954c3424f035474c635216227c8f
Showing with 2 additions and 11 deletions.
  1. +0 −9 src/core/providers/gdal/qgsgdalprovider.cpp
  2. +2 −2 src/core/raster/qgsrasterlayer.cpp
@@ -2670,15 +2670,6 @@ bool QgsGdalProvider::hasStatistics( int bandNo,
if ( !( stats & QgsRasterBandStats::Mean ) ) pdfMean = nullptr;
if ( !( stats & QgsRasterBandStats::StdDev ) ) pdfStdDev = nullptr;

// try to fetch the cached stats (bForce=FALSE)
// Unfortunately GDALGetRasterStatistics() does not work as expected according to
// API doc, if bApproxOK=false and bForce=false/true and exact statistics
// (from all raster pixels) are not available/cached, it should return CE_Warning.
// Instead, it is giving estimated (from sample) cached statistics and it returns CE_None.
// see above and https://trac.osgeo.org/gdal/ticket/4857
// -> Cannot used cached GDAL stats for exact
if ( !bApproxOK ) return false;

CPLErr myerval = GDALGetRasterStatistics( myGdalBand, bApproxOK, true, pdfMin, pdfMax, pdfMean, pdfStdDev );

if ( CE_None == myerval ) // CE_Warning if cached not found
@@ -469,9 +469,9 @@ QString QgsRasterLayer::htmlMetadata() const
myMetadata += tr( "n/a" );
myMetadata += QLatin1String( "</td>" );

if ( provider->hasStatistics( i ) )
if ( provider->hasStatistics( i, QgsRasterBandStats::Min | QgsRasterBandStats::Max, provider->extent(), SAMPLE_SIZE ) )
{
QgsRasterBandStats myRasterBandStats = provider->bandStatistics( i );
QgsRasterBandStats myRasterBandStats = provider->bandStatistics( i, QgsRasterBandStats::Min | QgsRasterBandStats::Max, provider->extent(), SAMPLE_SIZE );
myMetadata += QStringLiteral( "<td>" ) % QString::number( myRasterBandStats.minimumValue, 'f', 10 ) % QStringLiteral( "</td>" ) %
QStringLiteral( "<td>" ) % QString::number( myRasterBandStats.maximumValue, 'f', 10 ) % QStringLiteral( "</td>" );
}

0 comments on commit 49265a8

Please sign in to comment.