Skip to content
Permalink
Browse files

Raster: invalidate block on errors

  • Loading branch information
elpaso authored and nyalldawson committed Oct 5, 2020
1 parent 62d02b5 commit 7162ab8e3676ccfd9937eb0ce012119b6256ca7d
@@ -683,8 +683,9 @@ QgsRasterBlock *QgsGdalProvider::block( int bandNo, const QgsRectangle &extent,
}
if ( !readBlock( bandNo, extent, width, height, block->bits(), feedback ) )
{
QgsDebugMsg( QStringLiteral( "Error occurred while reading block" ) );
block->setError( { tr( "Error occurred while reading block." ), QStringLiteral( "GDAL" ) } );
block->setIsNoData();
block->setValid( false );
return block.release();
}
// apply scale and offset
@@ -20,6 +20,7 @@
#include "qgsrasterviewport.h"
#include "qgssymbollayerutils.h"
#include "qgsstyleentityvisitor.h"
#include "qgsmessagelog.h"

#include <QColor>
#include <QDomDocument>
@@ -497,9 +498,13 @@ QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromRas
{
break;
}
raster->extent();
const QgsRectangle rowExtent { fullExtent.xMinimum(), fullExtent.yMinimum() + yStep * row, fullExtent.xMaximum(), fullExtent.yMinimum() + yStep *( row + 1 ) };
std::unique_ptr<QgsRasterBlock> block { raster->block( bandNumber, rowExtent, raster->xSize(), 1, feedback ) };
if ( ! block->isValid() )
{
QgsMessageLog::logMessage( QStringLiteral( "Invalid block reading from raster. %1" ).arg( block->error().summary() ), QStringLiteral( "Raster" ) );
return data;
}
for ( col = 0; col < static_cast<qgssize>( raster->xSize() ); ++col )
{
if ( presentValues >= MAX_FLOAT_CLASSES )
@@ -529,7 +534,7 @@ QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromRas
}
if ( presentValues == MAX_FLOAT_CLASSES && ( col < static_cast<qgssize>( raster->xSize() ) || row < static_cast<qgssize>( raster->ySize() ) ) )
{
QgsDebugMsg( QStringLiteral( "Numer of classes exceeded maximum (%1)." ).arg( MAX_FLOAT_CLASSES ) );
QgsMessageLog::logMessage( QStringLiteral( "Number of classes exceeded maximum (%1)." ).arg( MAX_FLOAT_CLASSES ), QStringLiteral( "Raster" ) );
}
}
else
@@ -21,6 +21,7 @@
#include "qgsprovidermetadata.h"
#include "qgsrasterprojector.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgsapplication.h"

#include <QTime>
@@ -56,6 +57,8 @@ QgsRasterBlock *QgsRasterDataProvider::block( int bandNo, QgsRectangle const &b
if ( block->isEmpty() )
{
QgsDebugMsg( QStringLiteral( "Couldn't create raster block" ) );
block->setError( { tr( "Couldn't create raster block." ), QStringLiteral( "Raster" ) } );
block->setValid( false );
return block.release();
}

@@ -65,6 +68,8 @@ QgsRasterBlock *QgsRasterDataProvider::block( int bandNo, QgsRectangle const &b
if ( tmpExtent.isEmpty() )
{
QgsDebugMsg( QStringLiteral( "Extent outside provider extent" ) );
block->setError( { tr( "Extent outside provider extent." ), QStringLiteral( "Raster" ) } );
block->setValid( false );
block->setIsNoData();
return block.release();
}
@@ -113,6 +118,8 @@ QgsRasterBlock *QgsRasterDataProvider::block( int bandNo, QgsRectangle const &b
{
// Should not happen
QgsDebugMsg( QStringLiteral( "Row or column limits out of range" ) );
block->setError( { tr( "Row or column limits out of range" ), QStringLiteral( "Raster" ) } );
block->setValid( false );
return block.release();
}

@@ -149,6 +156,8 @@ QgsRasterBlock *QgsRasterDataProvider::block( int bandNo, QgsRectangle const &b
if ( !readBlock( bandNo, tmpExtent, tmpWidth, tmpHeight, tmpBlock->bits(), feedback ) )
{
QgsDebugMsg( QStringLiteral( "Error occurred while reading block" ) );
block->setError( { tr( "Error occurred while reading block." ), QStringLiteral( "Raster" ) } );
block->setValid( false );
block->setIsNoData();
return block.release();
}
@@ -174,6 +183,8 @@ QgsRasterBlock *QgsRasterDataProvider::block( int bandNo, QgsRectangle const &b
{
QgsDebugMsg( QStringLiteral( "Source row or column limits out of range" ) );
block->setIsNoData(); // so that the problem becomes obvious and fixed
block->setError( { tr( "Source row or column limits out of range." ), QStringLiteral( "Raster" ) } );
block->setValid( false );
return block.release();
}

@@ -202,6 +213,8 @@ QgsRasterBlock *QgsRasterDataProvider::block( int bandNo, QgsRectangle const &b
{
QgsDebugMsg( QStringLiteral( "Error occurred while reading block" ) );
block->setIsNoData();
block->setError( { tr( "Error occurred while reading block." ), QStringLiteral( "Raster" ) } );
block->setValid( false );
return block.release();
}
}

0 comments on commit 7162ab8

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