Skip to content
Permalink
Browse files

Do not persist estimated GDAL metadata

GDAL saves metadata like min and max values into a .aux.xml sidecar file next to raster files.
It does this always, even when the calculated values are estimated. In subsequent runs of GDAL processing tools
it will use these values as if they were reliable.

This patch takes care of deleting newly written .aux.xml files if there is a risk that they include estimated data.

Fix #19517  https://issues.qgis.org/issues/19517
  • Loading branch information
m-kuhn committed Oct 19, 2018
1 parent 190f938 commit 70d4a276da8eaa4c5b3e84c467b95a3611b4b9c7
Showing with 11 additions and 0 deletions.
  1. +9 −0 src/providers/gdal/qgsgdalprovider.cpp
  2. +2 −0 src/providers/gdal/qgsgdalprovider.h
@@ -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
{
@@ -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

0 comments on commit 70d4a27

Please sign in to comment.
You can’t perform that action at this time.