Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Unit tests for QgsRasterDataProvider::sample
  • Loading branch information
nyalldawson committed Jul 19, 2018
1 parent b747ff6 commit db8e536
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/src/core/testqgsrasterlayer.cpp
Expand Up @@ -85,6 +85,7 @@ class TestQgsRasterLayer : public QObject
void setRenderer();
void regression992(); //test for issue #992 - GeoJP2 images improperly displayed as all black
void testRefreshRendererIfNeeded();
void sample();


private:
Expand Down Expand Up @@ -720,5 +721,27 @@ void TestQgsRasterLayer::testRefreshRendererIfNeeded()
QGSCOMPARENOTNEAR( initMinVal, newMinVal, 1e-5 );
}

void TestQgsRasterLayer::sample()
{
QString fileName = mTestDataDir + "landsat-f32-b1.tif";

QFileInfo rasterFileInfo( fileName );
std::unique_ptr< QgsRasterLayer > rl = qgis::make_unique< QgsRasterLayer> ( rasterFileInfo.filePath(),
rasterFileInfo.completeBaseName() );
QVERIFY( rl->isValid() );
QVERIFY( !rl->dataProvider()->sample( QgsPointXY( 0, 0 ), 1 ).isValid() );
QCOMPARE( rl->dataProvider()->sample( QgsPointXY( 788461, 3344957 ), 1 ).toInt(), 125 );

fileName = mTestDataDir + "landsat_4326.tif";
rasterFileInfo = QFileInfo( fileName );
rl = qgis::make_unique< QgsRasterLayer> ( rasterFileInfo.filePath(),
rasterFileInfo.completeBaseName() );
QVERIFY( rl->isValid() );
QVERIFY( !rl->dataProvider()->sample( QgsPointXY( 0, 0 ), 1 ).isValid() );
QCOMPARE( rl->dataProvider()->sample( QgsPointXY( 17.943731, 30.230791 ), 1 ).toInt(), 125 );
QCOMPARE( rl->dataProvider()->sample( QgsPointXY( 17.943731, 30.230791 ), 2 ).toInt(), 139 );
QCOMPARE( rl->dataProvider()->sample( QgsPointXY( 17.943731, 30.230791 ), 3 ).toInt(), 111 );
}

QGSTEST_MAIN( TestQgsRasterLayer )
#include "testqgsrasterlayer.moc"

0 comments on commit db8e536

Please sign in to comment.