Class: QgsRasterCalculator

class qgis.analysis.QgsRasterCalculator

Bases: sip.wrapper

Performs raster layer calculations.

QgsRasterCalculator(formulaString: Optional[str], outputFile: Optional[str], outputFormat: Optional[str], outputExtent: QgsRectangle, 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 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

  • transformContext – coordinate transformation context

Added in version 3.8.

QgsRasterCalculator(formulaString: Optional[str], outputFile: Optional[str], outputFormat: Optional[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

Added in version 3.8.

QgsRasterCalculator(formulaString: Optional[str], outputFile: Optional[str], outputFormat: Optional[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: Optional[str], outputFile: Optional[str], outputFormat: Optional[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

QgsRasterCalculator(a0: QgsRasterCalculator)

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.

Added in version 3.4.

Return type:

str

processCalculation(self, feedback: QgsFeedback | None = 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 (Optional[QgsFeedback] = None)