Skip to content
Permalink
Browse files

Disable VSI cache before GDALRasterIO, workaround for GDAL ticket 5170,

fixes #8356
  • Loading branch information
blazek committed Aug 13, 2013
1 parent c96e099 commit 83d15a51ff279e31c81ceb56fcc83a153ef82327
@@ -405,7 +405,7 @@ void QgsGdalProvider::readBlock( int theBandNo, int xBlock, int yBlock, void *bl
// We have to read with correct data type consistent with other readBlock functions
int xOff = xBlock * mXBlockSize;
int yOff = yBlock * mYBlockSize;
GDALRasterIO( myGdalBand, GF_Read, xOff, yOff, mXBlockSize, mYBlockSize, block, mXBlockSize, mYBlockSize, ( GDALDataType ) mGdalDataType[theBandNo-1], 0, 0 );
gdalRasterIO( myGdalBand, GF_Read, xOff, yOff, mXBlockSize, mYBlockSize, block, mXBlockSize, mYBlockSize, ( GDALDataType ) mGdalDataType[theBandNo-1], 0, 0 );
}

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,
GDALRasterBandH gdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
GDALDataType type = ( GDALDataType )mGdalDataType[theBandNo-1];
CPLErrorReset();
CPLErr err = GDALRasterIO( gdalBand, GF_Read,
CPLErr err = gdalRasterIO( gdalBand, GF_Read,
srcLeft, srcTop, srcWidth, srcHeight,
( void * )tmpBlock,
tmpWidth, tmpHeight, type,
@@ -2533,7 +2533,7 @@ bool QgsGdalProvider::write( void* data, int band, int width, int height, int xO
{
return false;
}
return GDALRasterIO( rasterBand, GF_Write, xOffset, yOffset, width, height, data, width, height, GDALGetRasterDataType( rasterBand ), 0, 0 ) == CE_None;
return gdalRasterIO( rasterBand, GF_Write, xOffset, yOffset, width, height, data, width, height, GDALGetRasterDataType( rasterBand ), 0, 0 ) == CE_None;
}

bool QgsGdalProvider::setNoDataValue( int bandNo, double noDataValue )
@@ -294,3 +294,21 @@ GDALDatasetH QgsGdalProviderBase::gdalOpen( const char *pszFilename, GDALAccess

return hDS;
}

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 )
{
// 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

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 );
#endif

return err;
}
@@ -49,6 +49,10 @@ class QgsGdalProviderBase

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

/** 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 );

protected:

QGis::DataType dataTypeFromGdal( int theGdalDataType ) const;

0 comments on commit 83d15a5

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