QgsNineCellFilter class

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

Derived classes

class QgsDerivativeFilter
Adds the ability to calculate derivatives in x- and y-directions.
class QgsRuggednessFilter
Calculates the ruggedness index based on a 3x3 moving window.
class QgsTotalCurvatureFilter
Calculates total curvature as described by Wilson, Gallant (2000): terrain analysis.

Constructors, destructors, conversion operators

QgsNineCellFilter(const QString& inputFile, const QString& outputFile, const QString& outputFormat)
Constructor that takes input file, output file and output format (GDAL string)

Public functions

auto processNineCellWindow(float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33) -> float pure virtual
Calculates output value from nine input values.
auto processRaster(QgsFeedback* feedback = nullptr) -> int
Starts the calculation, reads from mInputFile and stores the result in mOutputFile.

Protected variables

float mInputNodataValue
The nodata value of the input layer.
float mOutputNodataValue
The nodata value of the output layer.
double mZFactor
Scale factor for z-value if x-/y- units are different to z-units (111120 for degree->meters and 370400 for degree->feet)

Function documentation

float QgsNineCellFilter::processNineCellWindow(float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33) pure virtual

Calculates output value from nine input values.

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

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

int QgsNineCellFilter::processRaster(QgsFeedback* feedback = nullptr)

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

Parameters
feedback feedback object that receives update and that is checked for cancelation.
Returns 0 in case of success