Skip to content
Permalink
Browse files

set correctly raster block nodata if layer extent or resolution is sm…

…aller than requested, fixes #7209
  • Loading branch information
blazek committed May 30, 2013
1 parent 4c02d7f commit a2fc3b42aafc31814916bb6d496166d155755a95
Showing with 13 additions and 3 deletions.
  1. +7 −1 src/core/raster/qgsrasterblock.cpp
  2. +6 −2 src/core/raster/qgsrasterdataprovider.cpp
@@ -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;
@@ -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;
}
@@ -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;
@@ -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 ) )
{

0 comments on commit a2fc3b4

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