Subgroup: Raster

Class: QgsRasterFileWriter

class qgis.core.QgsRasterFileWriter

Bases: sip.wrapper

The raster file writer which allows you to save a raster to a new file.

Methods

buildPyramidsFlag
createMultiBandRaster Create a raster file with given number of bands without initializing the pixel data.
createOneBandRaster Create a raster file with one band without initializing the pixel data.
createOptions
driverForExtension Returns the GDAL driver name for a specified file extension.
extensionsForFormat Returns a list of known file extensions for the given GDAL driver format.
filterForDriver Creates a filter for an GDAL driver key
maxTileHeight
maxTileWidth
outputFormat
outputProviderKey
outputUrl Returns the output URL for the raster.
pyramidsConfigOptions
pyramidsFormat
pyramidsList
pyramidsResampling
setBuildPyramidsFlag
setCreateOptions
setMaxTileHeight
setMaxTileWidth
setOutputFormat
setOutputProviderKey
setPyramidsConfigOptions
setPyramidsFormat
setPyramidsList
setPyramidsResampling
setTiledMode
supportedFiltersAndFormats Returns a list or pairs, with format filter string as first element and GDAL format key as second element.
supportedFormatExtensions Returns a list of file extensions for supported formats.
tiledMode
writeRaster Write raster file

Signals

Attributes

CreateDatasourceError
DestProviderError
Image
NoDataConflict
NoError
Raw
SortRecommended
SourceProviderError
WriteCanceled
WriteError
CreateDatasourceError = 3
DestProviderError = 2
class FilterFormatDetails

Bases: sip.wrapper

QgsRasterFileWriter.FilterFormatDetails(QgsRasterFileWriter.FilterFormatDetails)

driverName
filterString
Image = 1
class Mode

Bases: int

NoDataConflict = 5
NoError = 0
class RasterFormatOption

Bases: int

class RasterFormatOptions

Bases: sip.wrapper

QgsRasterFileWriter.RasterFormatOptions(Union[QgsRasterFileWriter.RasterFormatOptions, QgsRasterFileWriter.RasterFormatOption]) QgsRasterFileWriter.RasterFormatOptions(QgsRasterFileWriter.RasterFormatOptions)

Raw = 0
SortRecommended = 2
SourceProviderError = 1
WriteCanceled = 6
WriteError = 4
class WriterError

Bases: int

buildPyramidsFlag(self) → QgsRaster.RasterBuildPyramids
createMultiBandRaster(self, dataType: Qgis.DataType, width: int, height: int, extent: QgsRectangle, crs: QgsCoordinateReferenceSystem, nBands: int) → QgsRasterDataProvider

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.

Returns:Instance of data provider in editing mode (on success) or None on error.

Note

Does not work with tiled mode enabled.

New in version 3.0.

createOneBandRaster(self, dataType: Qgis.DataType, width: int, height: int, extent: QgsRectangle, crs: QgsCoordinateReferenceSystem) → QgsRasterDataProvider

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.

Returns:Instance of data provider in editing mode (on success) or None on error.

Note

Does not work with tiled mode enabled.

New in version 3.0.

createOptions(self) → List[str]
driverForExtension(extension: str) → str

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).

New in version 3.0.

extensionsForFormat(format: str) → List[str]

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).

New in version 3.0.

filterForDriver(driverName: str) → str

Creates a filter for an GDAL driver key

maxTileHeight(self) → int
maxTileWidth(self) → int
outputFormat(self) → str
outputProviderKey(self) → str
outputUrl(self) → str

Returns the output URL for the raster.

New in version 3.0.

pyramidsConfigOptions(self) → List[str]
pyramidsFormat(self) → QgsRaster.RasterPyramidsFormat
pyramidsList(self) → List[int]
pyramidsResampling(self) → str
setBuildPyramidsFlag(self, f: QgsRaster.RasterBuildPyramids)
setCreateOptions(self, list: Iterable[str])
setMaxTileHeight(self, h: int)
setMaxTileWidth(self, w: int)
setOutputFormat(self, format: str)
setOutputProviderKey(self, key: str)
setPyramidsConfigOptions(self, list: Iterable[str])
setPyramidsFormat(self, f: QgsRaster.RasterPyramidsFormat)
setPyramidsList(self, list: Iterable[int])
setPyramidsResampling(self, str: str)
setTiledMode(self, t: bool)
supportedFiltersAndFormats(options: Union[QgsRasterFileWriter.RasterFormatOptions, QgsRasterFileWriter.RasterFormatOption] = QgsRasterFileWriter.SortRecommended) → object

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.

supportedFormatExtensions(options: Union[QgsRasterFileWriter.RasterFormatOptions, QgsRasterFileWriter.RasterFormatOption] = QgsRasterFileWriter.SortRecommended) → List[str]

Returns a list of file extensions for supported formats.

The options argument can be used to control the sorting and filtering of returned formats.

New in version 3.0.

tiledMode(self) → bool
writeRaster(self, pipe: QgsRasterPipe, nCols: int, nRows: int, outputExtent: QgsRectangle, crs: QgsCoordinateReferenceSystem, feedback: QgsRasterBlockFeedback = None) → QgsRasterFileWriter.WriterError

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