Skip to content
Permalink
Browse files

Merge pull request #8438 from wonder-sk/fix-block-outside-raster-extent

Fix raster block output when block extent is outside of valid area
  • Loading branch information
wonder-sk committed Nov 8, 2018
2 parents 528c8a6 + 872c9a1 commit ad1bba2ac909417435bdd85c9dfb592acc3c09a5
Showing with 32 additions and 0 deletions.
  1. +7 −0 src/providers/gdal/qgsgdalprovider.cpp
  2. +25 −0 tests/src/providers/testqgsgdalprovider.cpp
@@ -640,6 +640,13 @@ QgsRasterBlock *QgsGdalProvider::block( int bandNo, const QgsRectangle &extent,
return block;
}

if ( !mExtent.intersects( extent ) )
{
// the requested extent is completely outside of the raster's extent - nothing to do
block->setIsNoData();
return block;
}

if ( !mExtent.contains( extent ) )
{
QRect subRect = QgsRasterBlock::subRect( extent, width, height, mExtent );
@@ -48,6 +48,7 @@ class TestQgsGdalProvider : public QObject
void scaleDataType(); //test resultant data types for int raster with float scale (#11573)
void warpedVrt(); //test loading raster which requires a warped vrt
void noData();
void noDataOutsideExtent();
void invalidNoDataInSourceIgnored();
void isRepresentableValue();
void mask();
@@ -151,6 +152,30 @@ void TestQgsGdalProvider::noData()
delete provider;
}

void TestQgsGdalProvider::noDataOutsideExtent()
{
QString raster = QStringLiteral( TEST_DATA_DIR ) + "/raster/band1_byte_ct_epsg4326.tif";
QgsDataProvider *provider = QgsProviderRegistry::instance()->createProvider( QStringLiteral( "gdal" ), raster, QgsDataProvider::ProviderOptions() );
QVERIFY( provider->isValid() );
QgsRasterDataProvider *rp = dynamic_cast< QgsRasterDataProvider * >( provider );
QVERIFY( rp );
if ( rp )
{
std::unique_ptr<QgsRasterBlock> block( rp->block( 1, QgsRectangle( 10, 10, 12, 12 ), 16, 16 ) );
QVERIFY( block );
QCOMPARE( block->width(), 16 );
QCOMPARE( block->height(), 16 );
for ( int y = 0; y < 16; ++y )
{
for ( int x = 0; x < 16; ++x )
{
QVERIFY( block->isNoData( y, x ) );
}
}
}
delete provider;
}

void TestQgsGdalProvider::invalidNoDataInSourceIgnored()
{
QString raster = QStringLiteral( TEST_DATA_DIR ) + "/raster/byte_with_nan_nodata.tif";

0 comments on commit ad1bba2

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