Skip to content
Permalink
Browse files

Workaround for GDAL ticket 5170, fixes #8356

  • Loading branch information
blazek committed Jul 27, 2013
1 parent 763d505 commit 299d152e2f6ddb626691ed7d66e99e21724b4832
@@ -139,7 +139,7 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri, bool update )
QString gdalUri = dataSourceUri();

CPLErrorReset();
mGdalBaseDataset = GDALOpen( TO8F( gdalUri ), mUpdate ? GA_Update : GA_ReadOnly );
mGdalBaseDataset = gdalOpen( TO8F( gdalUri ), mUpdate ? GA_Update : GA_ReadOnly );

if ( !mGdalBaseDataset )
{
@@ -1424,12 +1424,12 @@ QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> & theRaste
GDALClose( mGdalDataset );
//mGdalBaseDataset = GDALOpen( QFile::encodeName( dataSourceUri() ).constData(), GA_Update );

mGdalBaseDataset = GDALOpen( TO8F( dataSourceUri() ), GA_Update );
mGdalBaseDataset = gdalOpen( TO8F( dataSourceUri() ), GA_Update );

// if the dataset couldn't be opened in read / write mode, tell the user
if ( !mGdalBaseDataset )
{
mGdalBaseDataset = GDALOpen( TO8F( dataSourceUri() ), GA_ReadOnly );
mGdalBaseDataset = gdalOpen( TO8F( dataSourceUri() ), GA_ReadOnly );
//Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
mGdalDataset = mGdalBaseDataset;
return "ERROR_WRITE_FORMAT";
@@ -1521,7 +1521,7 @@ QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> & theRaste
//something bad happenend
//QString myString = QString (CPLGetLastError());
GDALClose( mGdalBaseDataset );
mGdalBaseDataset = GDALOpen( TO8F( dataSourceUri() ), mUpdate ? GA_Update : GA_ReadOnly );
mGdalBaseDataset = gdalOpen( TO8F( dataSourceUri() ), mUpdate ? GA_Update : GA_ReadOnly );
//Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
mGdalDataset = mGdalBaseDataset;

@@ -1576,7 +1576,7 @@ QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> & theRaste
QgsDebugMsg( "Reopening dataset ..." );
//close the gdal dataset and reopen it in read only mode
GDALClose( mGdalBaseDataset );
mGdalBaseDataset = GDALOpen( TO8F( dataSourceUri() ), mUpdate ? GA_Update : GA_ReadOnly );
mGdalBaseDataset = gdalOpen( TO8F( dataSourceUri() ), mUpdate ? GA_Update : GA_ReadOnly );
//Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
mGdalDataset = mGdalBaseDataset;
}
@@ -2029,7 +2029,7 @@ QGISEXTERN bool isValidRasterFileName( QString const & theFileNameQString, QStri

//open the file using gdal making sure we have handled locale properly
//myDataset = GDALOpen( QFile::encodeName( theFileNameQString ).constData(), GA_ReadOnly );
myDataset = GDALOpen( TO8F( fileName ), GA_ReadOnly );
myDataset = QgsGdalProviderBase::gdalOpen( TO8F( fileName ), GA_ReadOnly );
if ( !myDataset )
{
if ( CPLGetLastErrorNo() != CPLE_OpenFailed )
@@ -15,6 +15,9 @@
* *
***************************************************************************/

#define CPL_SUPRESS_CPLUSPLUS
#include "cpl_conv.h"

#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsgdalproviderbase.h"
@@ -273,3 +276,21 @@ QgsRectangle QgsGdalProviderBase::extent( GDALDatasetH gdalDataset )const
QgsRectangle extent( myGeoTransform[0], myYMin, myXMax, myGeoTransform[3] );
return extent;
}

GDALDatasetH QgsGdalProviderBase::gdalOpen( const char *pszFilename, GDALAccess eAccess )
{
// See http://hub.qgis.org/issues/8356 and http://trac.osgeo.org/gdal/ticket/5170
#if GDAL_VERSION_MAJOR == 1 && ( (GDAL_VERSION_MINOR == 9 && GDAL_VERSION_REV <= 2) || (GDAL_VERSION_MINOR == 10 && GDAL_VERSION_REV <= 0) )
char* pszOldVal = CPLStrdup( CPLGetConfigOption( "VSI_CACHE", "FALSE" ) );
CPLSetThreadLocalConfigOption( "VSI_CACHE", "FALSE" );
#endif

GDALDatasetH hDS = GDALOpen( pszFilename, eAccess );

#if GDAL_VERSION_MAJOR == 1 && ( (GDAL_VERSION_MINOR == 9 && GDAL_VERSION_REV <= 2) || (GDAL_VERSION_MINOR == 10 && GDAL_VERSION_REV <= 0) )
CPLSetThreadLocalConfigOption( "VSI_CACHE", pszOldVal );
CPLFree( pszOldVal );
#endif

return hDS;
}
@@ -46,6 +46,9 @@ class QgsGdalProviderBase

/** \brief ensures that GDAL drivers are registered, but only once */
static void registerGdalDrivers();

/** Wrapper function for GDALOpen to get around possible bugs in GDAL */
static GDALDatasetH gdalOpen( const char *pszFilename, GDALAccess eAccess );
protected:

QGis::DataType dataTypeFromGdal( int theGdalDataType ) const;

0 comments on commit 299d152

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