Skip to content
Permalink
Browse files
add test for createMultiBandRaster
  • Loading branch information
alexbruy committed May 23, 2017
1 parent fa6b5b0 commit ca7cd631d83314b62f6b8f6cc744949427ac3abe
Showing with 58 additions and 0 deletions.
  1. +58 −0 tests/src/core/testqgsrasterfilewriter.cpp
@@ -48,6 +48,7 @@ class TestQgsRasterFileWriter: public QObject

void writeTest();
void testCreateOneBandRaster();
void testCreateMultiBandRaster();
private:
bool writeTest( const QString &rasterName );
void log( const QString &msg );
@@ -211,6 +212,63 @@ void TestQgsRasterFileWriter::testCreateOneBandRaster()
delete rlayer;
}

void TestQgsRasterFileWriter::testCreateMultiBandRaster()
{
// generate unique filename (need to open the file first to generate it)
QTemporaryFile tmpFile;
tmpFile.open();
tmpFile.close();
QString filename = tmpFile.fileName();

QgsRectangle extent( 106.7, -6.2, 106.9, -6.1 );
int width = 200, height = 100, nBands = 1;

QgsRasterFileWriter writer( filename );
QgsRasterDataProvider *dp = writer.createMultiBandRaster( Qgis::Byte, width, height, extent, QgsCoordinateReferenceSystem( "EPSG:4326" ), nBands );
QVERIFY( dp );
QCOMPARE( dp->xSize(), width );
QCOMPARE( dp->ySize(), height );
QCOMPARE( dp->extent(), extent );
QCOMPARE( dp->bandCount(), 1 );
QCOMPARE( dp->dataType( 1 ), Qgis::Byte );
QVERIFY( dp->isEditable() );
delete dp;

QgsRasterLayer *rlayer = new QgsRasterLayer( filename, "tmp", "gdal" );
QVERIFY( rlayer->isValid() );
QCOMPARE( rlayer->width(), width );
QCOMPARE( rlayer->height(), height );
QCOMPARE( rlayer->extent(), extent );
QCOMPARE( rlayer->bandCount(), 1 );
QCOMPARE( rlayer->dataProvider()->dataType( 1 ), Qgis::Byte );
delete rlayer;

nBands = 3;
dp = writer.createMultiBandRaster( Qgis::Byte, width, height, extent, QgsCoordinateReferenceSystem( "EPSG:4326" ), nBands );
QVERIFY( dp );
QCOMPARE( dp->xSize(), width );
QCOMPARE( dp->ySize(), height );
QCOMPARE( dp->extent(), extent );
QCOMPARE( dp->bandCount(), nBands );
for ( int i = 1; i <= nBands; i++ )
{
QCOMPARE( dp->dataType( i ), Qgis::Byte );
}
QVERIFY( dp->isEditable() );
delete dp;

rlayer = new QgsRasterLayer( filename, "tmp", "gdal" );
QVERIFY( rlayer->isValid() );
QCOMPARE( rlayer->width(), width );
QCOMPARE( rlayer->height(), height );
QCOMPARE( rlayer->extent(), extent );
QCOMPARE( rlayer->bandCount(), nBands );
for ( int i = 1; i <= nBands; i++ )
{
QCOMPARE( rlayer->dataProvider()->dataType( i ), Qgis::Byte );
}
delete rlayer;
}

void TestQgsRasterFileWriter::log( const QString &msg )
{

0 comments on commit ca7cd63

Please sign in to comment.