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

rtype

QgsRaster.RasterBuildPyramids

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

rtype

List[str]

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

rtype

int

maxTileWidth

rtype

int

outputFormat

rtype

str

outputProviderKey

rtype

str

outputUrl

Returns the output URL for the raster.

pyramidsConfigOptions

rtype

List[str]

pyramidsFormat

rtype

QgsRaster.RasterPyramidsFormat

pyramidsList

rtype

List[int]

pyramidsResampling

rtype

str

setBuildPyramidsFlag

param f

setCreateOptions

param list

setMaxTileHeight

param h

setMaxTileWidth

param w

setOutputFormat

param format

setOutputProviderKey

param key

setPyramidsConfigOptions

param list

setPyramidsFormat

param f

setPyramidsList

param list

setPyramidsResampling

param str

setTiledMode

param t

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

rtype

bool

writeRaster

Write raster file

Attributes

CreateDatasourceError

DestProviderError

Image

NoDataConflict

NoError

Raw

SortRecommended

SourceProviderError

WriteCanceled

WriteError

CreateDatasourceError = 3
DestProviderError = 2
class FilterFormatDetails
class FilterFormatDetails(QgsRasterFileWriter.FilterFormatDetails)

Bases: sip.wrapper

driverName
filterString
Image = 1
class Mode

Bases: int

NoDataConflict = 5
NoError = 0
class RasterFormatOption

Bases: int

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

Bases: sip.wrapper

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

Bases: int

buildPyramidsFlag(self) QgsRaster.RasterBuildPyramids
Return type

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.

Return type

QgsRasterDataProvider

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.

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

Return type

QgsRasterDataProvider

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.

Parameters
createOptions(self) List[str]
Return type

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.

Parameters

extension (str) –

Return type

str

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.

Parameters

format (str) –

Return type

List[str]

filterForDriver(driverName: str) str

Creates a filter for an GDAL driver key

Parameters

driverName (str) –

Return type

str

maxTileHeight(self) int
Return type

int

maxTileWidth(self) int
Return type

int

outputFormat(self) str
Return type

str

outputProviderKey(self) str
Return type

str

outputUrl(self) str

Returns the output URL for the raster.

New in version 3.0.

Return type

str

pyramidsConfigOptions(self) List[str]
Return type

List[str]

pyramidsFormat(self) QgsRaster.RasterPyramidsFormat
Return type

QgsRaster.RasterPyramidsFormat

pyramidsList(self) List[int]
Return type

List[int]

pyramidsResampling(self) str
Return type

str

setBuildPyramidsFlag(self, f: QgsRaster.RasterBuildPyramids)
Parameters

f (QgsRaster.RasterBuildPyramids) –

setCreateOptions(self, list: Iterable[str])
Parameters

list (Iterable[str]) –

setMaxTileHeight(self, h: int)
Parameters

h (int) –

setMaxTileWidth(self, w: int)
Parameters

w (int) –

setOutputFormat(self, format: str)
Parameters

format (str) –

setOutputProviderKey(self, key: str)
Parameters

key (str) –

setPyramidsConfigOptions(self, list: Iterable[str])
Parameters

list (Iterable[str]) –

setPyramidsFormat(self, f: QgsRaster.RasterPyramidsFormat)
Parameters

f (QgsRaster.RasterPyramidsFormat) –

setPyramidsList(self, list: Iterable[int])
Parameters

list (Iterable[int]) –

setPyramidsResampling(self, str: str)
Parameters

str (str) –

setTiledMode(self, t: bool)
Parameters

t (bool) –

supportedFiltersAndFormats(options: Union[QgsRasterFileWriter.RasterFormatOptions, QgsRasterFileWriter.RasterFormatOption] = QgsRasterFileWriter.SortRecommended) List[QgsRasterFileWriter.FilterFormatDetails]

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.

Parameters

options (Union[QgsRasterFileWriter.RasterFormatOptions) –

Return type

List[QgsRasterFileWriter.FilterFormatDetails]

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.

Parameters

options (Union[QgsRasterFileWriter.RasterFormatOptions) –

Return type

List[str]

tiledMode(self) bool
Return type

bool

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

Write raster file

Parameters
  • pipe (QgsRasterPipe) – raster pipe

  • nCols (int) – number of output columns

  • nRows (int) – number of output rows (or -1 to automatically calculate row number to have square pixels)

  • outputExtent (QgsRectangle) – extent to output

  • crs (QgsCoordinateReferenceSystem) – crs to reproject to

  • feedback (QgsRasterBlockFeedback = None) – optional feedback object for progress reports

Deprecated since version QGIS: 3.8 use version with transformContext instead

writeRaster(self, pipe: QgsRasterPipe, nCols: int, nRows: int, outputExtent: QgsRectangle, crs: QgsCoordinateReferenceSystem, transformContext: QgsCoordinateTransformContext, 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

  • transformContext – coordinate transform context

  • feedback – optional feedback object for progress reports

New in version 3.8.

Return type

QgsRasterFileWriter.WriterError