Skip to content

Commit

Permalink
Code for cancellation of raster reading with GDAL 2 - disabled for now
Browse files Browse the repository at this point in the history
There are still some questions around it and I need to find some data
for thorough testing (many GDAL drivers do not support cancellation)
  • Loading branch information
wonder-sk committed Jul 24, 2016
1 parent 7b8c1c5 commit 940883b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -437,7 +437,6 @@ void QgsGdalProvider::readBlock( int theBandNo, int xBlock, int yBlock, void *bl

void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent, int thePixelWidth, int thePixelHeight, void *theBlock, QgsRasterBlockFeedback* feedback )
{
Q_UNUSED( feedback ); // TODO: use with GDAL 2
QgsDebugMsg( "thePixelWidth = " + QString::number( thePixelWidth ) );
QgsDebugMsg( "thePixelHeight = " + QString::number( thePixelHeight ) );
QgsDebugMsg( "theExtent: " + theExtent.toString() );
Expand Down Expand Up @@ -608,11 +607,12 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
GDALRasterBandH gdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
GDALDataType type = ( GDALDataType )mGdalDataType.at( theBandNo - 1 );
CPLErrorReset();

CPLErr err = gdalRasterIO( gdalBand, GF_Read,
srcLeft, srcTop, srcWidth, srcHeight,
( void * )tmpBlock,
tmpWidth, tmpHeight, type,
0, 0 );
0, 0, feedback );

if ( err != CPLE_None )
{
Expand Down
29 changes: 28 additions & 1 deletion src/providers/gdal/qgsgdalproviderbase.cpp
Expand Up @@ -280,7 +280,17 @@ 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 )
static int CPL_STDCALL _gdalProgressFnWithFeedback( double dfComplete, const char *pszMessage, void *pProgressArg )
{
Q_UNUSED( dfComplete );
Q_UNUSED( pszMessage );

QgsRasterBlockFeedback* feedback = static_cast<QgsRasterBlockFeedback*>( pProgressArg );
return !feedback->isCancelled();
}


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, QgsRasterBlockFeedback* feedback )
{
// 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) )
Expand All @@ -289,7 +299,24 @@ CPLErr QgsGdalProviderBase::gdalRasterIO( GDALRasterBandH hBand, GDALRWFlag eRWF
QgsDebugMsg( "Disabled VSI_CACHE" );
#endif

#if GDAL_VERSION_MAJOR >= 2
GDALRasterIOExtraArg extra;
INIT_RASTERIO_EXTRA_ARG( extra );
if ( 0 && feedback ) // disabled!
{
// Currently the cancellation is disabled... When RasterIO call is cancelled,
// GDAL returns CE_Failure with error code = 0 (CPLE_None), however one would
// expect to get CPLE_UserInterrupt to clearly identify that the failure was
// caused by the cancellation and not that something dodgy is going on.
// Are both error codes acceptable?
extra.pfnProgress = _gdalProgressFnWithFeedback;
extra.pProgressData = ( void* ) feedback;
}
CPLErr err = GDALRasterIOEx( hBand, eRWFlag, nXOff, nYOff, nXSize, nYSize, pData, nBufXSize, nBufYSize, eBufType, nPixelSpace, nLineSpace, &extra );
#else
Q_UNUSED( feedback );
CPLErr err = GDALRasterIO( hBand, eRWFlag, nXOff, nYOff, nXSize, nYSize, pData, nBufXSize, nBufYSize, eBufType, nPixelSpace, nLineSpace );
#endif

#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 );
Expand Down
2 changes: 1 addition & 1 deletion src/providers/gdal/qgsgdalproviderbase.h
Expand Up @@ -49,7 +49,7 @@ class QgsGdalProviderBase
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 );
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, QgsRasterBlockFeedback* feedback = nullptr );

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

0 comments on commit 940883b

Please sign in to comment.