Skip to content

Commit

Permalink
Disable VSI cache before GDALGetOverviewCount, workaround for GDAL ti…
Browse files Browse the repository at this point in the history
…cket 5170, hopefully fixes #8356
  • Loading branch information
blazek committed Aug 18, 2013
1 parent 2a29483 commit 6a1a4be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions src/providers/gdal/qgsgdalproviderbase.cpp
Expand Up @@ -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;
Expand All @@ -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;
}
2 changes: 2 additions & 0 deletions src/providers/gdal/qgsgdalproviderbase.h
Expand Up @@ -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;
Expand Down

0 comments on commit 6a1a4be

Please sign in to comment.