Skip to content

Commit a2fc3b4

Browse files
committed
set correctly raster block nodata if layer extent or resolution is smaller than requested, fixes #7209
1 parent 4c02d7f commit a2fc3b4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/core/raster/qgsrasterblock.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -846,9 +846,13 @@ bool QgsRasterBlock::createNoDataBitmap()
846846

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

854+
QgsDebugMsg( QString( "theWidth = %1 theHeight = %2 xRes = %3 yRes = %4" ).arg( theWidth ).arg( theHeight ).arg( xRes ).arg( yRes ) );
855+
852856
int top = 0;
853857
int bottom = theHeight - 1;
854858
int left = 0;
@@ -871,5 +875,7 @@ QRect QgsRasterBlock::subRect( const QgsRectangle & theExtent, int theWidth, int
871875
{
872876
right = qRound(( theSubExtent.xMaximum() - theExtent.xMinimum() ) / xRes ) - 1;
873877
}
874-
return QRect( left, top, right - left + 1, bottom - top + 1 );
878+
QRect subRect = QRect( left, top, right - left + 1, bottom - top + 1 );
879+
QgsDebugMsg( QString( "subRect: %1 %2 %3 %4" ).arg( subRect.x() ).arg( subRect.y() ).arg( subRect.width() ).arg( subRect.height() ) );
880+
return subRect;
875881
}

src/core/raster/qgsrasterdataprovider.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ QgsRasterBlock * QgsRasterDataProvider::block( int theBandNo, QgsRectangle cons
9999
{
100100
// Read smaller extent or lower resolution
101101

102+
if ( !extent().contains( theExtent ) )
103+
{
104+
QRect subRect = QgsRasterBlock::subRect( theExtent, theWidth, theHeight, extent() );
105+
block->setIsNoDataExcept( subRect );
106+
}
107+
102108
// Calculate row/col limits (before tmpExtent is aligned)
103109
int fromRow = qRound(( theExtent.yMaximum() - tmpExtent.yMaximum() ) / yRes );
104110
int toRow = qRound(( theExtent.yMaximum() - tmpExtent.yMinimum() ) / yRes ) - 1;
@@ -139,8 +145,6 @@ QgsRasterBlock * QgsRasterDataProvider::block( int theBandNo, QgsRectangle cons
139145
QgsDebugMsg( QString( "Reading smaller block tmpWidth = %1 theHeight = %2" ).arg( tmpWidth ).arg( tmpHeight ) );
140146
QgsDebugMsg( QString( "tmpExtent = %1" ).arg( tmpExtent.toString() ) );
141147

142-
block->setIsNoData();
143-
144148
QgsRasterBlock *tmpBlock;
145149
if ( srcHasNoDataValue( theBandNo ) && useSrcNoDataValue( theBandNo ) )
146150
{

0 commit comments

Comments
 (0)