Class: QgsRasterCalculator

class qgis.analysis.QgsRasterCalculator(formulaString: str, outputFile: str, outputFormat: str, outputExtent: QgsRectangle, nOutputColumns: int, nOutputRows: int, rasterEntries: Iterable[QgsRasterCalculatorEntry], transformContext: QgsCoordinateTransformContext)

Bases: sip.wrapper

QgsRasterCalculator constructor.

Parameters
  • formulaString (str) – formula for raster calculation

  • outputFile (str) – output file path

  • outputFormat (str) – output file format

  • outputExtent (QgsRectangle) – output extent. CRS for output is taken from first entry in rasterEntries.

  • nOutputColumns (int) – number of columns in output raster

  • nOutputRows (int) – number of rows in output raster

  • rasterEntries (Iterable[QgsRasterCalculatorEntry]) – list of referenced raster layers

  • transformContext (QgsCoordinateTransformContext) – coordinate transformation context

New in version 3.8.

QgsRasterCalculator(formulaString: str, outputFile: str, outputFormat: str, outputExtent: QgsRectangle, outputCrs: QgsCoordinateReferenceSystem, nOutputColumns: int, nOutputRows: int, rasterEntries: Iterable[QgsRasterCalculatorEntry], transformContext: QgsCoordinateTransformContext) QgsRasterCalculator constructor.

Parameters
  • formulaString – formula for raster calculation

  • outputFile – output file path

  • outputFormat – output file format

  • outputExtent – output extent, CRS is specified by outputCrs parameter

  • outputCrs – destination CRS for output raster

  • nOutputColumns – number of columns in output raster

  • nOutputRows – number of rows in output raster

  • rasterEntries – list of referenced raster layers

  • transformContext – coordinate transformation context

New in version 3.8.

QgsRasterCalculator(formulaString: str, outputFile: str, outputFormat: str, outputExtent: QgsRectangle, nOutputColumns: int, nOutputRows: int, rasterEntries: Iterable[QgsRasterCalculatorEntry]) QgsRasterCalculator constructor.

Parameters
  • formulaString – formula for raster calculation

  • outputFile – output file path

  • outputFormat – output file format

  • outputExtent – output extent. CRS for output is taken from first entry in rasterEntries.

  • nOutputColumns – number of columns in output raster

  • nOutputRows – number of rows in output raster

  • rasterEntries – list of referenced raster layers

Deprecated since version QGIS: 3.8 use the version with transformContext instead

QgsRasterCalculator(formulaString: str, outputFile: str, outputFormat: str, outputExtent: QgsRectangle, outputCrs: QgsCoordinateReferenceSystem, nOutputColumns: int, nOutputRows: int, rasterEntries: Iterable[QgsRasterCalculatorEntry]) QgsRasterCalculator constructor.

Parameters
  • formulaString – formula for raster calculation

  • outputFile – output file path

  • outputFormat – output file format

  • outputExtent – output extent, CRS is specified by outputCrs parameter

  • outputCrs – destination CRS for output raster

  • nOutputColumns – number of columns in output raster

  • nOutputRows – number of rows in output raster

  • rasterEntries – list of referenced raster layers

Deprecated since version QGIS: 3.8 use the version with transformContext instead

New in version 2.10.

QgsRasterCalculator(QgsRasterCalculator)

Performs raster layer calculations.

Methods

lastError

Returns a description of the last error encountered.

processCalculation

Starts the calculation and writes a new raster.

Attributes

BandError

CalculationError

Canceled

CreateOutputError

InputLayerError

MemoryError

ParserError

Success

BandError = 6
CalculationError = 7
Canceled = 3
CreateOutputError = 1
InputLayerError = 2
MemoryError = 5
ParserError = 4
class Result

Bases: int

Success = 0
lastError(self) → str

Returns a description of the last error encountered.

New in version 3.4.

Return type

str

processCalculation(self, feedback: QgsFeedback = None)QgsRasterCalculator.Result

Starts the calculation and writes a new raster.

The optional feedback argument can be used for progress reporting and cancellation support.

Return type

QgsRasterCalculator.Result

Returns

QgsRasterCalculator.Success in case of success. If an error is encountered then a description of the error can be obtained by calling lastError().

Parameters

feedback (QgsFeedback = None) –