SAGA-GIS Tool Library Documentation (v9.1.2)

Tool Grid Calculator

The Grid Calculator calculates a new grid based on existing grids and a mathematical formula. The grid variables in the formula begin with the letter 'g' followed by a position index, which corresponds to the order of the grids in the input grid list (i.e.: g1, g2, g3, ... correspond to the first, second, third, ... grid in list). Grids from other systems than the default one can be addressed likewise using the letter 'h' (h1, h2, h3, ...), which correspond to the 'Grids from different Systems' list.

Example: sin(g1) * g2 + 2 * h1

To make complex formulas look more intuitive you have the option to use shortcuts. Shortcuts are defined following the formula separated by semicolons as 'shortcut = expression'.

Example: ifelse(lt(NDVI, 0.4), nodata(), NDVI); NDVI = (g1 - g2) / (g1 + g2)

The following operators are available for the formula definition:

+Addition
-Subtraction
*Multiplication
/Division
abs(x)Absolute Value
mod(x, y)Returns the floating point remainder of x/y
int(x)Returns the integer part of floating point value x
sqr(x)Square
sqrt(x)Square Root
exp(x)Exponential
pow(x, y)Returns x raised to the power of y
x ^ yReturns x raised to the power of y
ln(x)Natural Logarithm
log(x)Base 10 Logarithm
pi()Returns the value of Pi
sin(x)Sine, expects radians
cos(x)Cosine, expects radians
tan(x)Tangent, expects radians
asin(x)Arcsine, returns radians
acos(x)Arccosine, returns radians
atan(x)Arctangent, returns radians
atan2(x, y)Arctangent of x/y, returns radians
min(x, y)Returns the minimum of values x and y
max(x, y)Returns the maximum of values x and y
gt(x, y)Returns true (1), if x is greater than y, else false (0)
x > yReturns true (1), if x is greater than y, else false (0)
lt(x, y)Returns true (1), if x is less than y, else false (0)
x < yReturns true (1), if x is less than y, else false (0)
eq(x, y)Returns true (1), if x equals y, else false (0)
x = yReturns true (1), if x equals y, else false (0)
and(x, y)Returns true (1), if both x and y are true (i.e. not 0)
or(x, y)Returns true (1), if at least one of both x and y is true (i.e. not 0)
ifelse(c, x, y)Returns x, if condition c is true (i.e. not 0), else y
rand_u(x, y)Random number, uniform distribution with minimum x and maximum y
rand_g(x, y)Random number, Gaussian distribution with mean x and standard deviation y
xpos(), ypos()The coordinate (x/y) for the center of the currently processed cell
col(), row()The currently processed cell's column/row index
ncols(), nrows()Number of the grid system's columns/rows
nodata(), nodata(g)No-data value of the resulting (empty) or requested grid (g = g1...gn, h1...hn)
cellsize(), cellsize(g)Cell size of the resulting (empty) or requested grid (g = h1...hn)
cellarea(), cellarea(g)Cell area of the resulting (empty) or requested grid (g = h1...hn)
xmin(), xmin(g)Left bound of the resulting (empty) or requested grid (g = h1...hn)
xmax(), xmax(g)Right bound of the resulting (empty) or requested grid (g = h1...hn)
xrange(), xrange(g)Left to right range of the resulting (empty) or requested grid (g = h1...hn)
ymin(), ymin(g)Lower bound of the resulting (empty) or requested grid (g = h1...hn)
ymax(), ymax(g)Upper bound of the resulting (empty) or requested grid (g = h1...hn)
yrange(), yrange(g)Lower to upper range of the resulting (empty) or requested grid (g = h1...hn)
zmin(g)Minimum value of the requested grid (g = g1...gn, h1...hn)
zmax(g)Maximum value of the requested grid (g = g1...gn, h1...hn)
zrange(g)Value range of the requested grid (g = g1...gn, h1...hn)
zmean(g)Mean value of the requested grid (g = g1...gn, h1...hn)
zstddev(g)Standard deviation of the requested grid (g = g1...gn, h1...hn)

Parameters

 NameTypeIdentifierDescriptionConstraints
InputGrids (*)Grid list, input, optionalGRIDSin the formula these grids are addressed in order of the list as 'g1, g2, g3, ...'-
Grids from different Systems (*)Grid list, input, optionalXGRIDSin the formula these grids are addressed in order of the list as 'h1, h2, h3, ...'-
OutputResultGrid, outputRESULT--
OptionsGrid SystemGrid systemPARAMETERS_GRID_SYSTEM--
ResamplingChoiceRESAMPLING-Available Choices:
[0] Nearest Neighbour
[1] Bilinear Interpolation
[2] Bicubic Spline Interpolation
[3] B-Spline Interpolation
Default: 3
FormulaTextFORMULA-Default: (g1 - g2) / (g1 + g2)
NameTextNAME-Default: Calculation
Take FormulaBooleanFNAME-Default: 0
Use No-DataBooleanUSE_NODATACheck this in order to include no-data cells in the calculation.Default: 0
Data TypeChoiceTYPE-Available Choices:
[0] bit
[1] unsigned 1 byte integer
[2] signed 1 byte integer
[3] unsigned 2 byte integer
[4] signed 2 byte integer
[5] unsigned 4 byte integer
[6] signed 4 byte integer
[7] 4 byte floating point number
[8] 8 byte floating point number
Default: 7
(*) optional

Command-line

Usage: saga_cmd grid_calculus 1 [-RESAMPLING <str>] [-FORMULA <str>] [-NAME <str>] [-FNAME <str>] [-USE_NODATA <str>] [-TYPE <str>] [-GRIDS <str>] [-XGRIDS <str>] [-RESULT <str>]
  -RESAMPLING:<str>	Resampling
	Choice
	Available Choices:
	[0] Nearest Neighbour
	[1] Bilinear Interpolation
	[2] Bicubic Spline Interpolation
	[3] B-Spline Interpolation
	Default: 3
  -FORMULA:<str>   	Formula
	Text
	Default: (g1 - g2) / (g1 + g2)
  -NAME:<str>      	Name
	Text
	Default: Calculation
  -FNAME:<str>     	Take Formula
	Boolean
	Default: 0
  -USE_NODATA:<str>	Use No-Data
	Boolean
	Default: 0
  -TYPE:<str>      	Data Type
	Choice
	Available Choices:
	[0] bit
	[1] unsigned 1 byte integer
	[2] signed 1 byte integer
	[3] unsigned 2 byte integer
	[4] signed 2 byte integer
	[5] unsigned 4 byte integer
	[6] signed 4 byte integer
	[7] 4 byte floating point number
	[8] 8 byte floating point number
	Default: 7
  -GRIDS:<str>     	Grids
	Grid list, input, optional
  -XGRIDS:<str>    	Grids from different Systems
	Grid list, input, optional
  -RESULT:<str>    	Result
	Grid, output