Class: QgsNineCellFilter

Base class for raster analysis methods that work with a 3x3 cell filter and calculate the value of each cell based on the cell value and the eight neighbour cells.

Common examples are slope and aspect calculation in DEMs. Subclasses only implement the method that calculates the new value from the nine values. Everything else (reading file, writing file) is done by this subclass

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: processNineCellWindow()

Class Hierarchy

Inheritance diagram of qgis.analysis.QgsNineCellFilter

Subclasses

QgsDerivativeFilter

Adds the ability to calculate derivatives in x- and y-directions.

QgsRuggednessFilter

Calculates the ruggedness index based on a 3x3 moving window.

QgsTotalCurvatureFilter

Calculates total curvature as described by Wilson, Gallant (2000): terrain analysis.

Enums

Result

Abstract Methods

processNineCellWindow

Calculates output value from nine input values.

Methods

cellSizeX

cellSizeY

creationOptions

Returns the list of data source creation options which will be used when creating the output raster file.

inputNodataValue

outputNodataValue

processRaster

Starts the calculation, reads from mInputFile and stores the result in mOutputFile

setCellSizeX

setCellSizeY

setCreationOptions

Sets a list of data source creation options to use when creating the output raster file.

setInputNodataValue

setOutputNodataValue

setZFactor

zFactor

class qgis.analysis.QgsNineCellFilter[source]

Bases: object

__init__(inputFile: str | None, outputFile: str | None, outputFormat: str | None)

Constructor that takes input file, output file and output format (GDAL string)

Parameters:
  • inputFile (Optional[str])

  • outputFile (Optional[str])

  • outputFormat (Optional[str])

__init__(a0: QgsNineCellFilter)
Parameters:

a0 (QgsNineCellFilter)

class Result(*values)

Bases: IntEnum

Added in version 3.44.

  • Success: Operation completed successfully

  • InputLayerError: Error reading input file

  • DriverError: Could not open the driver for the specified format

  • CreateOutputError: Error creating output file

  • InputBandError: Error reading input raster band

  • OutputBandError: Error reading output raster band

  • RasterSizeError: Raster height is too small (need at least 3 rows)

  • Canceled: User canceled calculation

Canceled = 7
CreateOutputError = 3
DriverError = 2
InputBandError = 4
InputLayerError = 1
OutputBandError = 5
RasterSizeError = 6
Success = 0
cellSizeX(self) float[source]
Return type:

float

cellSizeY(self) float[source]
Return type:

float

creationOptions(self) List[str][source]

Returns the list of data source creation options which will be used when creating the output raster file.

Added in version 3.44.

Return type:

List[str]

inputNodataValue(self) float[source]
Return type:

float

outputNodataValue(self) float[source]
Return type:

float

abstract processNineCellWindow(self)[source]

Calculates output value from nine input values. The input values and the output value can be equal to the nodata value if not present or outside of the border. Must be implemented by subclasses.

First index of the input cell is the row, second index is the column

Parameters:
  • x11 – surrounding cell top left

  • x21 – surrounding cell central left

  • x31 – surrounding cell bottom left

  • x12 – surrounding cell top central

  • x22 – the central cell for which the value will be calculated

  • x32 – surrounding cell bottom central

  • x13 – surrounding cell top right

  • x23 – surrounding cell central right

  • x33 – surrounding cell bottom right

Returns:

the calculated cell value for the central cell x22

processRaster(self, feedback: QgsFeedback | None = None) QgsNineCellFilter.Result[source]

Starts the calculation, reads from mInputFile and stores the result in mOutputFile

Parameters:

feedback (Optional[QgsFeedback] = None) – feedback object that receives update and that is checked for cancellation.

Return type:

QgsNineCellFilter.Result

Returns:

QgsNineCellFilter.Result.Success in case of success or error value on failure.

setCellSizeX(self, size: float)[source]
Parameters:

size (float)

setCellSizeY(self, size: float)[source]
Parameters:

size (float)

setCreationOptions(self, options: Iterable[str | None])[source]

Sets a list of data source creation options to use when creating the output raster file.

Added in version 3.44.

Parameters:

options (Iterable[Optional[str]])

setInputNodataValue(self, value: float)[source]
Parameters:

value (float)

setOutputNodataValue(self, value: float)[source]
Parameters:

value (float)

setZFactor(self, factor: float)[source]
Parameters:

factor (float)

zFactor(self) float[source]
Return type:

float