Skip to content
Permalink
Browse files

Unit tests for QgsRasterDataProvider::sample

  • Loading branch information
nyalldawson committed Jul 12, 2018
1 parent b747ff6 commit db8e5364f5f72bbc84f02fddb6cbe30153c69bc5
Showing with 23 additions and 0 deletions.
  1. +23 −0 tests/src/core/testqgsrasterlayer.cpp
@@ -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:
@@ -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.
You can’t perform that action at this time.