Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #8303 from m-kuhn/doNotPersistEstimatedMetadata
Do not persist estimated metadata
  • Loading branch information
m-kuhn committed Oct 25, 2018
2 parents 607cd3e + 87fddae commit 75a170d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -105,6 +105,7 @@ QgsGdalProvider::QgsGdalProvider( const QString &uri, QgsError error )
, mYBlockSize( 0 )
, mGdalBaseDataset( nullptr )
, mGdalDataset( nullptr )
, mStatisticsAreReliable( false )
{
mGeoTransform[0] = 0;
mGeoTransform[1] = 1;
Expand All @@ -127,6 +128,7 @@ QgsGdalProvider::QgsGdalProvider( const QString &uri, bool update )
, mYBlockSize( 0 )
, mGdalBaseDataset( nullptr )
, mGdalDataset( nullptr )
, mStatisticsAreReliable( false )
{
mGeoTransform[0] = 0;
mGeoTransform[1] = 1;
Expand Down Expand Up @@ -240,7 +242,15 @@ QgsGdalProvider::~QgsGdalProvider()
}
if ( mGdalDataset )
{
// Check if already a PAM (persistent auxiliary metadata) file exists
QString pamFile = dataSourceUri() + 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();
}
}

Expand Down Expand Up @@ -2443,6 +2453,7 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo, int theStats,
myerval = GDALComputeRasterStatistics( myGdalBand, bApproxOK,
&pdfMin, &pdfMax, &pdfMean, &pdfStdDev,
progressCallback, &myProg );
mStatisticsAreReliable = true;
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions src/providers/gdal/qgsgdalprovider.h
Expand Up @@ -301,6 +301,8 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase

/** \brief sublayers list saved for subsequent access */
QStringList mSubLayers;

bool mStatisticsAreReliable;
};

#endif
Expand Down

0 comments on commit 75a170d

Please sign in to comment.