Skip to content

Commit

Permalink
[API] convenience API call to create empty raster file with given
Browse files Browse the repository at this point in the history
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 9272dc0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions python/core/raster/qgsrasterfilewriter.sip
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/core/raster/qgsrasterfilewriter.cpp
Expand Up @@ -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 )
Expand Down
11 changes: 11 additions & 0 deletions src/core/raster/qgsrasterfilewriter.h
Expand Up @@ -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
Expand Down

0 comments on commit 9272dc0

Please sign in to comment.