Skip to content

Commit

Permalink
set correctly raster block nodata if layer extent or resolution is sm…
Browse files Browse the repository at this point in the history
…aller than requested, fixes #7209
  • Loading branch information
blazek committed May 30, 2013
1 parent 4c02d7f commit a2fc3b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/core/raster/qgsrasterblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,13 @@ bool QgsRasterBlock::createNoDataBitmap()

QRect QgsRasterBlock::subRect( const QgsRectangle & theExtent, int theWidth, int theHeight, const QgsRectangle & theSubExtent )
{
QgsDebugMsg( "theExtent = " + theExtent.toString() );
QgsDebugMsg( "theSubExtent = " + theSubExtent.toString() );
double xRes = theExtent.width() / theWidth;
double yRes = theExtent.height() / theHeight;

QgsDebugMsg( QString( "theWidth = %1 theHeight = %2 xRes = %3 yRes = %4" ).arg( theWidth ).arg( theHeight ).arg( xRes ).arg( yRes ) );

int top = 0;
int bottom = theHeight - 1;
int left = 0;
Expand All @@ -871,5 +875,7 @@ QRect QgsRasterBlock::subRect( const QgsRectangle & theExtent, int theWidth, int
{
right = qRound(( theSubExtent.xMaximum() - theExtent.xMinimum() ) / xRes ) - 1;
}
return QRect( left, top, right - left + 1, bottom - top + 1 );
QRect subRect = QRect( left, top, right - left + 1, bottom - top + 1 );
QgsDebugMsg( QString( "subRect: %1 %2 %3 %4" ).arg( subRect.x() ).arg( subRect.y() ).arg( subRect.width() ).arg( subRect.height() ) );
return subRect;
}
8 changes: 6 additions & 2 deletions src/core/raster/qgsrasterdataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ QgsRasterBlock * QgsRasterDataProvider::block( int theBandNo, QgsRectangle cons
{
// Read smaller extent or lower resolution

if ( !extent().contains( theExtent ) )
{
QRect subRect = QgsRasterBlock::subRect( theExtent, theWidth, theHeight, extent() );
block->setIsNoDataExcept( subRect );
}

// Calculate row/col limits (before tmpExtent is aligned)
int fromRow = qRound(( theExtent.yMaximum() - tmpExtent.yMaximum() ) / yRes );
int toRow = qRound(( theExtent.yMaximum() - tmpExtent.yMinimum() ) / yRes ) - 1;
Expand Down Expand Up @@ -139,8 +145,6 @@ QgsRasterBlock * QgsRasterDataProvider::block( int theBandNo, QgsRectangle cons
QgsDebugMsg( QString( "Reading smaller block tmpWidth = %1 theHeight = %2" ).arg( tmpWidth ).arg( tmpHeight ) );
QgsDebugMsg( QString( "tmpExtent = %1" ).arg( tmpExtent.toString() ) );

block->setIsNoData();

QgsRasterBlock *tmpBlock;
if ( srcHasNoDataValue( theBandNo ) && useSrcNoDataValue( theBandNo ) )
{
Expand Down

0 comments on commit a2fc3b4

Please sign in to comment.