QgsRasterFileWriter class
The raster file writer which allows you to save a raster to a new file.
Contents
Public types
- struct FilterFormatDetails
- Details of available filters and formats.
- enum Mode { Raw = 0, Image = 1 }
- enum RasterFormatOption { SortRecommended = 1 << 1 }
- Options for sorting and filtering raster formats.
- enum WriterError { NoError = 0, SourceProviderError = 1, DestProviderError = 2, CreateDatasourceError = 3, WriteError = 4, NoDataConflict = 5, WriteCanceled = 6 }
Public static functions
- static auto driverForExtension(const QString& extension) -> QString
- Returns the GDAL driver name for a specified file extension.
- static auto extensionsForFormat(const QString& format) -> QStringList
- Returns a list of known file extensions for the given GDAL driver format.
- static auto filterForDriver(const QString& driverName) -> QString
- Creates a filter for an GDAL driver key.
-
static auto supportedFiltersAndFormats(RasterFormatOptions options = SortRecommended) -> QList<QgsRasterFileWriter::
FilterFormatDetails> - Returns a list or pairs, with format filter string as first element and GDAL format key as second element.
- static auto supportedFormatExtensions(RasterFormatOptions options = SortRecommended) -> QStringList
- Returns a list of file extensions for supported formats.
Public functions
-
auto createMultiBandRaster(Qgis::
DataType dataType, int width, int height, const QgsRectangle& extent, const QgsCoordinateReferenceSystem& crs, int nBands) -> QgsRasterDataProvider* - Create a raster file with given number of bands without initializing the pixel data.
-
auto createOneBandRaster(Qgis::
DataType dataType, int width, int height, const QgsRectangle& extent, const QgsCoordinateReferenceSystem& crs) -> QgsRasterDataProvider* - Create a raster file with one band without initializing the pixel data.
- auto outputUrl() const -> QString
- Returns the output URL for the raster.
- auto writeRaster(const QgsRasterPipe* pipe, int nCols, int nRows, const QgsRectangle& outputExtent, const QgsCoordinateReferenceSystem& crs, QgsRasterBlockFeedback* feedback = nullptr) -> WriterError
- Write raster file.
Enum documentation
enum QgsRasterFileWriter:: RasterFormatOption
Options for sorting and filtering raster formats.
| Enumerators | |
|---|---|
| SortRecommended |
Use recommended sort order, with extremely commonly used formats listed first. |
enum QgsRasterFileWriter:: WriterError
| Enumerators | |
|---|---|
| NoError | |
| SourceProviderError | |
| DestProviderError | |
| CreateDatasourceError | |
| WriteError | |
| NoDataConflict |
Internal error if a value used for 'no data' was found in input. |
| WriteCanceled |
Writing was manually canceled. |
Function documentation
static QString QgsRasterFileWriter:: driverForExtension(const QString& extension)
Returns the GDAL driver name for a specified file extension.
E.g. the driver name for the ".tif" extension is "GTiff". If no suitable drivers are found then an empty string is returned.
Note that this method works for all GDAL drivers, including those without create support (and which are not supported by QgsRasterFileWriter).
static QStringList QgsRasterFileWriter:: extensionsForFormat(const QString& format)
Returns a list of known file extensions for the given GDAL driver format.
E.g. returns "tif", "tiff" for the format "GTiff".
If no matching format driver is found an empty list will be returned.
Note that this method works for all GDAL drivers, including those without create support (and which are not supported by QgsRasterFileWriter).
static QList<QgsRasterFileWriter:: FilterFormatDetails> QgsRasterFileWriter:: supportedFiltersAndFormats(RasterFormatOptions options = SortRecommended)
Returns a list or pairs, with format filter string as first element and GDAL format key as second element.
Relies on GDAL_DMD_EXTENSIONS metadata, if it is empty corresponding driver will be skipped even if supported.
The options argument can be used to control the sorting and filtering of returned formats.
static QStringList QgsRasterFileWriter:: supportedFormatExtensions(RasterFormatOptions options = SortRecommended)
Returns a list of file extensions for supported formats.
The options argument can be used to control the sorting and filtering of returned formats.
QgsRasterDataProvider* QgsRasterFileWriter:: createMultiBandRaster(Qgis:: DataType dataType,
int width,
int height,
const QgsRectangle& extent,
const QgsCoordinateReferenceSystem& crs,
int nBands)
Create a raster file with given number of bands without initializing the pixel data.
| Returns | Instance of data provider in editing mode (on success) or nullptr on error. |
|---|
Returned provider may be used to initialize the raster using writeBlock() calls. Ownership of the returned provider is passed to the caller.
QgsRasterDataProvider* QgsRasterFileWriter:: createOneBandRaster(Qgis:: DataType dataType,
int width,
int height,
const QgsRectangle& extent,
const QgsCoordinateReferenceSystem& crs)
Create a raster file with one band without initializing the pixel data.
| Returns | Instance of data provider in editing mode (on success) or nullptr on error. |
|---|
Returned provider may be used to initialize the raster using writeBlock() calls. Ownership of the returned provider is passed to the caller.
QString QgsRasterFileWriter:: outputUrl() const
Returns the output URL for the raster.
WriterError QgsRasterFileWriter:: writeRaster(const QgsRasterPipe* pipe,
int nCols,
int nRows,
const QgsRectangle& outputExtent,
const QgsCoordinateReferenceSystem& crs,
QgsRasterBlockFeedback* feedback = nullptr)
Write raster file.
| Parameters | |
|---|---|
| pipe | raster pipe |
| nCols | number of output columns |
| nRows | number of output rows (or -1 to automatically calculate row number to have square pixels) |
| outputExtent | extent to output |
| crs | crs to reproject to |
| feedback | optional feedback object for progress reports |