Class: QgsRasterFileWriter¶
- class qgis.core.QgsRasterFileWriter¶
Bases:
sip.wrapper
The raster file writer which allows you to save a raster to a new file.
The writer defaults to creating GeoTIFF outputs using GDAL. Alternative formats and data providers can be used by calling
setOutputFormat()
andsetOutputProviderKey()
.QgsRasterFileWriter(outputUrl: str) Constructor for
QgsRasterFileWriter
, writing to the specified output URL/filename.QgsRasterFileWriter(
QgsRasterFileWriter
)Enums
alias of
RasterExportType
alias of
RasterFileWriterResult
Methods
Returns the pyramid building option.
Create a raster file with given number of bands without initializing the pixel data.
Create a raster file with one band without initializing the pixel data.
Returns the list of data source creation options which will be used when creating the output raster file.
Returns the GDAL driver name for a specified file
extension
.Returns a list of known file extensions for the given GDAL driver
format
.Creates a filter for an GDAL driver key
Returns the maximum tile height (in pixels) for tiled outputs.
Returns the maximum tile width (in pixels) for tiled outputs.
Returns the output format.
Returns the name of the data provider for the raster output.
Returns the output URL (filename) for the raster.
Returns the list of configuration options used when creating the pyramids for the output raster file.
Returns the raster pyramid format.
Returns the list of pyramids which will be created for the output file.
- rtype:
str
Sets the pyramid building option.
Sets a list of data source creation options to use when creating the output raster file.
Sets the maximum tile height (in pixels) for tiled outputs.
Sets the maximum tile width (in pixels) for tiled outputs.
Sets the output
format
.Sets the name of the data provider for the raster output.
Sets a
list
of configuration options to use when creating the pyramids for the output raster file.Sets the raster pyramid format.
Sets the
list
of pyramids which will be created for the output file.- param str:
Sets whether the output should be tiled.
Returns a list or pairs, with format filter string as first element and GDAL format key as second element.
Returns a list of file extensions for supported formats.
Returns whether the output will be tiled.
Write raster file
Attributes
- class FilterFormatDetails¶
- class FilterFormatDetails(QgsRasterFileWriter.FilterFormatDetails)
Bases:
sip.wrapper
- driverName¶
- filterString¶
- Mode¶
alias of
RasterExportType
- class RasterFormatOption¶
Bases:
int
- class RasterFormatOptions¶
- class RasterFormatOptions(Union[QgsRasterFileWriter.RasterFormatOptions, QgsRasterFileWriter.RasterFormatOption])
- class RasterFormatOptions(QgsRasterFileWriter.RasterFormatOptions)
Bases:
sip.wrapper
- SortRecommended = 2¶
- WriterError¶
alias of
RasterFileWriterResult
- buildPyramidsFlag(self) Qgis.RasterBuildPyramidOption ¶
Returns the pyramid building option.
See also
- Return type:
- 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:
- Returns:
Instance of data provider in editing mode (on success) or
None
on error.
Note
Does not work with tiled mode enabled.
- Parameters:
dataType (Qgis.DataType) –
width (int) –
height (int) –
extent (QgsRectangle) –
crs (QgsCoordinateReferenceSystem) –
nBands (int) –
- 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:
- Returns:
Instance of data provider in editing mode (on success) or
None
on error.
Note
Does not work with tiled mode enabled.
- Parameters:
dataType (Qgis.DataType) –
width (int) –
height (int) –
extent (QgsRectangle) –
crs (QgsCoordinateReferenceSystem) –
- createOptions(self) List[str] ¶
Returns the list of data source creation options which will be used when creating the output raster file.
See also
- 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
).- 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
).- 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 ¶
Returns the maximum tile height (in pixels) for tiled outputs.
See also
See also
See also
- Return type:
int
- maxTileWidth(self) int ¶
Returns the maximum tile width (in pixels) for tiled outputs.
See also
See also
See also
- Return type:
int
- outputFormat(self) str ¶
Returns the output format.
For GDAL disk based outputs this will match the GDAL driver name, e.g. “GTiff” for GeoTiff exports.
See also
- Return type:
str
- outputProviderKey(self) str ¶
Returns the name of the data provider for the raster output.
See also
- Return type:
str
- outputUrl(self) str ¶
Returns the output URL (filename) for the raster.
- Return type:
str
- pyramidsConfigOptions(self) List[str] ¶
Returns the list of configuration options used when creating the pyramids for the output raster file.
See also
- Return type:
List[str]
- pyramidsFormat(self) Qgis.RasterPyramidFormat ¶
Returns the raster pyramid format.
See also
- Return type:
- pyramidsList(self) List[int] ¶
Returns the list of pyramids which will be created for the output file.
See also
- Return type:
List[int]
- pyramidsResampling(self) str ¶
- Return type:
str
- setBuildPyramidsFlag(self, f: Qgis.RasterBuildPyramidOption)¶
Sets the pyramid building option.
See also
- Parameters:
- setCreateOptions(self, list: Iterable[str])¶
Sets a list of data source creation options to use when creating the output raster file.
See also
- Parameters:
list (Iterable[str]) –
- setMaxTileHeight(self, h: int)¶
Sets the maximum tile height (in pixels) for tiled outputs.
See also
See also
See also
- Parameters:
h (int) –
- setMaxTileWidth(self, w: int)¶
Sets the maximum tile width (in pixels) for tiled outputs.
See also
See also
See also
- Parameters:
w (int) –
- setOutputFormat(self, format: str)¶
Sets the output
format
.For GDAL disk based outputs this should match the GDAL driver name, e.g. “GTiff” for GeoTiff exports.
See also
- Parameters:
format (str) –
- setOutputProviderKey(self, key: str)¶
Sets the name of the data provider for the raster output.
E.g. set to “gdal” to use GDAL to create disk based raster files.
See also
- Parameters:
key (str) –
- setPyramidsConfigOptions(self, list: Iterable[str])¶
Sets a
list
of configuration options to use when creating the pyramids for the output raster file.See also
- Parameters:
list (Iterable[str]) –
- setPyramidsFormat(self, f: Qgis.RasterPyramidFormat)¶
Sets the raster pyramid format.
See also
- Parameters:
f (Qgis.RasterPyramidFormat) –
- setPyramidsList(self, list: Iterable[int])¶
Sets the
list
of pyramids which will be created for the output file.See also
- Parameters:
list (Iterable[int]) –
- setPyramidsResampling(self, str: str)¶
- Parameters:
str (str) –
- setTiledMode(self, t: bool)¶
Sets whether the output should be tiled.
Tiled outputs will automatically split the raster into multiple parts, based on the
maxTileWidth()
value.See also
- Parameters:
t (bool) –
- supportedFiltersAndFormats(options: 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.See also
- Parameters:
options (Union[QgsRasterFileWriter.RasterFormatOptions) –
- Return type:
- supportedFormatExtensions(options: 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.See also
- Parameters:
options (Union[QgsRasterFileWriter.RasterFormatOptions) –
- Return type:
List[str]
- tiledMode(self) bool ¶
Returns whether the output will be tiled.
See also
- Return type:
bool
- writeRaster(self, pipe: QgsRasterPipe, nCols: int, nRows: int, outputExtent: QgsRectangle, crs: QgsCoordinateReferenceSystem, feedback: QgsRasterBlockFeedback = None) Qgis.RasterFileWriterResult ¶
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) -> Qgis.RasterFileWriterResult 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: