Skip to content
Permalink
Browse files

Disable VSI cache before GDALGetOverviewCount, workaround for GDAL ti…

…cket 5170, hopefully fixes #8356
  • Loading branch information
blazek committed Aug 18, 2013
1 parent 2a29483 commit 6a1a4be72223df55996bb2fb403c9515c807bc25
@@ -2353,7 +2353,7 @@ void QgsGdalProvider::initBaseDataset()
}

// check if this file has pyramids
mHasPyramids = GDALGetOverviewCount( myGDALBand ) > 0;
mHasPyramids = gdalGetOverviewCount( myGDALBand ) > 0;

// Get the layer's projection info and set up the
// QgsCoordinateTransform for this layer
@@ -283,13 +283,15 @@ GDALDatasetH QgsGdalProviderBase::gdalOpen( const char *pszFilename, GDALAccess
#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" );
QgsDebugMsg( "Disabled VSI_CACHE" );
#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 );
QgsDebugMsg( "Reset VSI_CACHE" );
#endif

return hDS;
@@ -301,14 +303,36 @@ CPLErr QgsGdalProviderBase::gdalRasterIO( GDALRasterBandH hBand, GDALRWFlag eRWF
#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" );
QgsDebugMsg( "Disabled VSI_CACHE" );
#endif

CPLErr err = GDALRasterIO( hBand, eRWFlag, nXOff, nYOff, nXSize, nYSize, pData, nBufXSize, nBufYSize, eBufType, nPixelSpace, nLineSpace );

#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 );
QgsDebugMsg( "Reset VSI_CACHE" );
#endif

return err;
}

int QgsGdalProviderBase::gdalGetOverviewCount( GDALRasterBandH hBand )
{
// 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" );
QgsDebugMsg( "Disabled VSI_CACHE" );
#endif

int count = GDALGetOverviewCount( hBand );

#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 );
QgsDebugMsg( "Reset VSI_CACHE" );
#endif

return count;
}
@@ -53,6 +53,8 @@ class QgsGdalProviderBase
/** Wrapper function for GDALRasterIO to get around possible bugs in GDAL */
static CPLErr gdalRasterIO( GDALRasterBandH hBand, GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize, void * pData, int nBufXSize, int nBufYSize, GDALDataType eBufType, int nPixelSpace, int nLineSpace );

/** Wrapper function for GDALRasterIO to get around possible bugs in GDAL */
static int gdalGetOverviewCount( GDALRasterBandH hBand );
protected:

QGis::DataType dataTypeFromGdal( int theGdalDataType ) const;

0 comments on commit 6a1a4be

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