Skip to content

Commit 83d15a5

Browse files
committed
Disable VSI cache before GDALRasterIO, workaround for GDAL ticket 5170, fixes #8356
1 parent c96e099 commit 83d15a5

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void QgsGdalProvider::readBlock( int theBandNo, int xBlock, int yBlock, void *bl
405405
// We have to read with correct data type consistent with other readBlock functions
406406
int xOff = xBlock * mXBlockSize;
407407
int yOff = yBlock * mYBlockSize;
408-
GDALRasterIO( myGdalBand, GF_Read, xOff, yOff, mXBlockSize, mYBlockSize, block, mXBlockSize, mYBlockSize, ( GDALDataType ) mGdalDataType[theBandNo-1], 0, 0 );
408+
gdalRasterIO( myGdalBand, GF_Read, xOff, yOff, mXBlockSize, mYBlockSize, block, mXBlockSize, mYBlockSize, ( GDALDataType ) mGdalDataType[theBandNo-1], 0, 0 );
409409
}
410410

411411
void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent, int thePixelWidth, int thePixelHeight, void *theBlock )
@@ -580,7 +580,7 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
580580
GDALRasterBandH gdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
581581
GDALDataType type = ( GDALDataType )mGdalDataType[theBandNo-1];
582582
CPLErrorReset();
583-
CPLErr err = GDALRasterIO( gdalBand, GF_Read,
583+
CPLErr err = gdalRasterIO( gdalBand, GF_Read,
584584
srcLeft, srcTop, srcWidth, srcHeight,
585585
( void * )tmpBlock,
586586
tmpWidth, tmpHeight, type,
@@ -2533,7 +2533,7 @@ bool QgsGdalProvider::write( void* data, int band, int width, int height, int xO
25332533
{
25342534
return false;
25352535
}
2536-
return GDALRasterIO( rasterBand, GF_Write, xOffset, yOffset, width, height, data, width, height, GDALGetRasterDataType( rasterBand ), 0, 0 ) == CE_None;
2536+
return gdalRasterIO( rasterBand, GF_Write, xOffset, yOffset, width, height, data, width, height, GDALGetRasterDataType( rasterBand ), 0, 0 ) == CE_None;
25372537
}
25382538

25392539
bool QgsGdalProvider::setNoDataValue( int bandNo, double noDataValue )

src/providers/gdal/qgsgdalproviderbase.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,21 @@ GDALDatasetH QgsGdalProviderBase::gdalOpen( const char *pszFilename, GDALAccess
294294

295295
return hDS;
296296
}
297+
298+
CPLErr QgsGdalProviderBase::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 )
299+
{
300+
// See http://hub.qgis.org/issues/8356 and http://trac.osgeo.org/gdal/ticket/5170
301+
#if GDAL_VERSION_MAJOR == 1 && ( (GDAL_VERSION_MINOR == 9 && GDAL_VERSION_REV <= 2) || (GDAL_VERSION_MINOR == 10 && GDAL_VERSION_REV <= 0) )
302+
char* pszOldVal = CPLStrdup( CPLGetConfigOption( "VSI_CACHE", "FALSE" ) );
303+
CPLSetThreadLocalConfigOption( "VSI_CACHE", "FALSE" );
304+
#endif
305+
306+
CPLErr err = GDALRasterIO( hBand, eRWFlag, nXOff, nYOff, nXSize, nYSize, pData, nBufXSize, nBufYSize, eBufType, nPixelSpace, nLineSpace );
307+
308+
#if GDAL_VERSION_MAJOR == 1 && ( (GDAL_VERSION_MINOR == 9 && GDAL_VERSION_REV <= 2) || (GDAL_VERSION_MINOR == 10 && GDAL_VERSION_REV <= 0) )
309+
CPLSetThreadLocalConfigOption( "VSI_CACHE", pszOldVal );
310+
CPLFree( pszOldVal );
311+
#endif
312+
313+
return err;
314+
}

src/providers/gdal/qgsgdalproviderbase.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class QgsGdalProviderBase
4949

5050
/** Wrapper function for GDALOpen to get around possible bugs in GDAL */
5151
static GDALDatasetH gdalOpen( const char *pszFilename, GDALAccess eAccess );
52+
53+
/** Wrapper function for GDALRasterIO to get around possible bugs in GDAL */
54+
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 );
55+
5256
protected:
5357

5458
QGis::DataType dataTypeFromGdal( int theGdalDataType ) const;

0 commit comments

Comments
 (0)