Skip to content

Commit 75a170d

Browse files
authored
Merge pull request #8303 from m-kuhn/doNotPersistEstimatedMetadata
Do not persist estimated metadata
2 parents 607cd3e + 87fddae commit 75a170d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/providers/gdal/qgsgdalprovider.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ QgsGdalProvider::QgsGdalProvider( const QString &uri, QgsError error )
105105
, mYBlockSize( 0 )
106106
, mGdalBaseDataset( nullptr )
107107
, mGdalDataset( nullptr )
108+
, mStatisticsAreReliable( false )
108109
{
109110
mGeoTransform[0] = 0;
110111
mGeoTransform[1] = 1;
@@ -127,6 +128,7 @@ QgsGdalProvider::QgsGdalProvider( const QString &uri, bool update )
127128
, mYBlockSize( 0 )
128129
, mGdalBaseDataset( nullptr )
129130
, mGdalDataset( nullptr )
131+
, mStatisticsAreReliable( false )
130132
{
131133
mGeoTransform[0] = 0;
132134
mGeoTransform[1] = 1;
@@ -240,7 +242,15 @@ QgsGdalProvider::~QgsGdalProvider()
240242
}
241243
if ( mGdalDataset )
242244
{
245+
// Check if already a PAM (persistent auxiliary metadata) file exists
246+
QString pamFile = dataSourceUri() + QLatin1String( ".aux.xml" );
247+
bool pamFileAlreadyExists = QFileInfo( pamFile ).exists();
248+
243249
GDALClose( mGdalDataset );
250+
251+
// If GDAL created a PAM file right now by using estimated metadata, delete it right away
252+
if ( !mStatisticsAreReliable && !pamFileAlreadyExists && QFileInfo( pamFile ).exists() )
253+
QFile( pamFile ).remove();
244254
}
245255
}
246256

@@ -2443,6 +2453,7 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo, int theStats,
24432453
myerval = GDALComputeRasterStatistics( myGdalBand, bApproxOK,
24442454
&pdfMin, &pdfMax, &pdfMean, &pdfStdDev,
24452455
progressCallback, &myProg );
2456+
mStatisticsAreReliable = true;
24462457
}
24472458
else
24482459
{

src/providers/gdal/qgsgdalprovider.h

+2
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
301301

302302
/** \brief sublayers list saved for subsequent access */
303303
QStringList mSubLayers;
304+
305+
bool mStatisticsAreReliable;
304306
};
305307

306308
#endif

0 commit comments

Comments
 (0)