diff --git a/src/providers/gdal/qgsgdalprovider.cpp b/src/providers/gdal/qgsgdalprovider.cpp index 8ea5b43e0866..804992363302 100644 --- a/src/providers/gdal/qgsgdalprovider.cpp +++ b/src/providers/gdal/qgsgdalprovider.cpp @@ -470,7 +470,15 @@ QgsGdalProvider::~QgsGdalProvider() } if ( mGdalDataset ) { + // Check if already a PAM (persistent auxiliary metadata) file exists + QString pamFile = dataSourceUri( true ) + QLatin1String( ".aux.xml" ); + bool pamFileAlreadyExists = QFileInfo( pamFile ).exists(); + GDALClose( mGdalDataset ); + + // If GDAL created a PAM file right now by using estimated metadata, delete it right away + if ( !mStatisticsAreReliable && !pamFileAlreadyExists && QFileInfo( pamFile ).exists() ) + QFile( pamFile ).remove(); } if ( mpParent && *mpParent == this ) @@ -2468,6 +2476,7 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int bandNo, int stats, const myerval = GDALComputeRasterStatistics( myGdalBand, bApproxOK, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev, progressCallback, &myProg ); + mStatisticsAreReliable = true; } else { diff --git a/src/providers/gdal/qgsgdalprovider.h b/src/providers/gdal/qgsgdalprovider.h index 641aeae2220d..4ab99d4d315d 100644 --- a/src/providers/gdal/qgsgdalprovider.h +++ b/src/providers/gdal/qgsgdalprovider.h @@ -296,6 +296,8 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase * Converts a world (\a x, \a y) coordinate to a pixel \a row and \a col. */ bool worldToPixel( double x, double y, int &col, int &row ) const; + + bool mStatisticsAreReliable = false; }; #endif