Skip to content

Commit db8e536

Browse files
committedJul 19, 2018
Unit tests for QgsRasterDataProvider::sample
1 parent b747ff6 commit db8e536

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
 

‎tests/src/core/testqgsrasterlayer.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class TestQgsRasterLayer : public QObject
8585
void setRenderer();
8686
void regression992(); //test for issue #992 - GeoJP2 images improperly displayed as all black
8787
void testRefreshRendererIfNeeded();
88+
void sample();
8889

8990

9091
private:
@@ -720,5 +721,27 @@ void TestQgsRasterLayer::testRefreshRendererIfNeeded()
720721
QGSCOMPARENOTNEAR( initMinVal, newMinVal, 1e-5 );
721722
}
722723

724+
void TestQgsRasterLayer::sample()
725+
{
726+
QString fileName = mTestDataDir + "landsat-f32-b1.tif";
727+
728+
QFileInfo rasterFileInfo( fileName );
729+
std::unique_ptr< QgsRasterLayer > rl = qgis::make_unique< QgsRasterLayer> ( rasterFileInfo.filePath(),
730+
rasterFileInfo.completeBaseName() );
731+
QVERIFY( rl->isValid() );
732+
QVERIFY( !rl->dataProvider()->sample( QgsPointXY( 0, 0 ), 1 ).isValid() );
733+
QCOMPARE( rl->dataProvider()->sample( QgsPointXY( 788461, 3344957 ), 1 ).toInt(), 125 );
734+
735+
fileName = mTestDataDir + "landsat_4326.tif";
736+
rasterFileInfo = QFileInfo( fileName );
737+
rl = qgis::make_unique< QgsRasterLayer> ( rasterFileInfo.filePath(),
738+
rasterFileInfo.completeBaseName() );
739+
QVERIFY( rl->isValid() );
740+
QVERIFY( !rl->dataProvider()->sample( QgsPointXY( 0, 0 ), 1 ).isValid() );
741+
QCOMPARE( rl->dataProvider()->sample( QgsPointXY( 17.943731, 30.230791 ), 1 ).toInt(), 125 );
742+
QCOMPARE( rl->dataProvider()->sample( QgsPointXY( 17.943731, 30.230791 ), 2 ).toInt(), 139 );
743+
QCOMPARE( rl->dataProvider()->sample( QgsPointXY( 17.943731, 30.230791 ), 3 ).toInt(), 111 );
744+
}
745+
723746
QGSTEST_MAIN( TestQgsRasterLayer )
724747
#include "testqgsrasterlayer.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.