Skip to content
Permalink
Browse files
[API] convenience API call to create empty raster file with given
number of bands. Will be useful for porting raster analysis code
to use QgsRasterBlock instead of GDAL calls.

Follow up ff8d912
  • Loading branch information
alexbruy committed May 23, 2017
1 parent 90bef91 commit 9272dc0f7c254e8f12f10477c5e3becfdedd5b2d
Showing with 38 additions and 0 deletions.
  1. +15 −0 python/core/raster/qgsrasterfilewriter.sip
  2. +12 −0 src/core/raster/qgsrasterfilewriter.cpp
  3. +11 −0 src/core/raster/qgsrasterfilewriter.h
@@ -53,6 +53,21 @@ class QgsRasterFileWriter
:rtype: QgsRasterDataProvider
%End

QgsRasterDataProvider *createRaster( Qgis::DataType dataType,
int width, int height, const QgsRectangle &extent,
int nBands, const QgsCoordinateReferenceSystem &crs ) /Factory/;
%Docstring
Create a raster file with given number of bands 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.
:return: Instance of data provider in editing mode (on success) or None on error.
.. versionadded:: 3.0
:rtype: QgsRasterDataProvider
%End

WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = 0 );
%Docstring
@@ -41,6 +41,18 @@ QgsRasterDataProvider *QgsRasterFileWriter::createOneBandRaster( Qgis::DataType
return initOutput( width, height, crs, geoTransform, 1, dataType, QList<bool>(), QList<double>() );
}

QgsRasterDataProvider *QgsRasterFileWriter::createRaster( Qgis::DataType dataType, int width, int height, const QgsRectangle &extent, int nBands, const QgsCoordinateReferenceSystem &crs )
{
if ( mTiledMode )
return nullptr; // does not make sense with tiled mode

double pixelSize;
double geoTransform[6];
globalOutputParameters( extent, width, height, geoTransform, pixelSize );

return initOutput( width, height, crs, geoTransform, nBands, dataType, QList<bool>(), QList<double>() );
}

QgsRasterFileWriter::QgsRasterFileWriter( const QString &outputUrl )
: mMode( Raw )
, mOutputUrl( outputUrl )
@@ -67,6 +67,17 @@ class CORE_EXPORT QgsRasterFileWriter
const QgsRectangle &extent,
const QgsCoordinateReferenceSystem &crs ) SIP_FACTORY;

/** Create a raster file with given number of bands 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 Instance of data provider in editing mode (on success) or nullptr on error.
* \since QGIS 3.0
*/
QgsRasterDataProvider *createRaster( Qgis::DataType dataType,
int width, int height, const QgsRectangle &extent,
int nBands, const QgsCoordinateReferenceSystem &crs ) SIP_FACTORY;

/** Write raster file
\param pipe raster pipe
\param nCols number of output columns

0 comments on commit 9272dc0

Please sign in to comment.