mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Make the one band raster creation method return data provider
This commit is contained in:
parent
7b27079de9
commit
ff8d912147
@ -30,14 +30,16 @@ class QgsRasterFileWriter
|
||||
QgsRasterFileWriter( const QString& outputUrl );
|
||||
|
||||
/** Create a raster file with one band without initializing the pixel data.
|
||||
* Returned provider may be used to initialize the raster using writeBlock() calls.
|
||||
* Ownership of the returned provider is passed to the caller.
|
||||
* @note Does not work with tiled mode enabled.
|
||||
* @returns true when the raster has been created successfully
|
||||
* @returns Instance of data provider in editing mode (on success) or null on error.
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
bool createOneBandRaster( Qgis::DataType dataType,
|
||||
QgsRasterDataProvider* createOneBandRaster( Qgis::DataType dataType,
|
||||
int width, int height,
|
||||
const QgsRectangle& extent,
|
||||
const QgsCoordinateReferenceSystem& crs );
|
||||
const QgsCoordinateReferenceSystem& crs ) /Factory/;
|
||||
|
||||
/** Write raster file
|
||||
@param pipe raster pipe
|
||||
|
@ -29,19 +29,16 @@
|
||||
#include <QTextStream>
|
||||
#include <QMessageBox>
|
||||
|
||||
bool QgsRasterFileWriter::createOneBandRaster( Qgis::DataType dataType, int width, int height, const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs )
|
||||
QgsRasterDataProvider* QgsRasterFileWriter::createOneBandRaster( Qgis::DataType dataType, int width, int height, const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs )
|
||||
{
|
||||
if ( mTiledMode )
|
||||
return false; // does not make sense with tiled mode
|
||||
return nullptr; // does not make sense with tiled mode
|
||||
|
||||
double pixelSize;
|
||||
double geoTransform[6];
|
||||
globalOutputParameters( extent, width, height, geoTransform, pixelSize );
|
||||
|
||||
QgsRasterDataProvider* destProvider = initOutput( width, height, crs, geoTransform, 1, dataType, QList<bool>(), QList<double>() );
|
||||
bool res = destProvider != nullptr;
|
||||
delete destProvider;
|
||||
return res;
|
||||
return initOutput( width, height, crs, geoTransform, 1, dataType, QList<bool>(), QList<double>() );
|
||||
}
|
||||
|
||||
QgsRasterFileWriter::QgsRasterFileWriter( const QString& outputUrl )
|
||||
|
@ -56,11 +56,13 @@ class CORE_EXPORT QgsRasterFileWriter
|
||||
QgsRasterFileWriter( const QString& outputUrl );
|
||||
|
||||
/** Create a raster file with one band without initializing the pixel data.
|
||||
* Returned provider may be used to initialize the raster using writeBlock() calls.
|
||||
* Ownership of the returned provider is passed to the caller.
|
||||
* @note Does not work with tiled mode enabled.
|
||||
* @returns true when the raster has been created successfully
|
||||
* @returns Instance of data provider in editing mode (on success) or null on error.
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
bool createOneBandRaster( Qgis::DataType dataType,
|
||||
QgsRasterDataProvider* createOneBandRaster( Qgis::DataType dataType,
|
||||
int width, int height,
|
||||
const QgsRectangle& extent,
|
||||
const QgsCoordinateReferenceSystem& crs );
|
||||
|
@ -191,8 +191,15 @@ void TestQgsRasterFileWriter::testCreateOneBandRaster()
|
||||
int width = 200, height = 100;
|
||||
|
||||
QgsRasterFileWriter writer( filename );
|
||||
bool res = writer.createOneBandRaster( Qgis::Byte, width, height, extent, QgsCoordinateReferenceSystem( "EPSG:4326" ) );
|
||||
QVERIFY( res );
|
||||
QgsRasterDataProvider* dp = writer.createOneBandRaster( Qgis::Byte, width, height, extent, QgsCoordinateReferenceSystem( "EPSG:4326" ) );
|
||||
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() );
|
||||
@ -201,6 +208,7 @@ void TestQgsRasterFileWriter::testCreateOneBandRaster()
|
||||
QCOMPARE( rlayer->extent(), extent );
|
||||
QCOMPARE( rlayer->bandCount(), 1 );
|
||||
QCOMPARE( rlayer->dataProvider()->dataType( 1 ), Qgis::Byte );
|
||||
delete rlayer;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user