rsaga.grid.calculus {RSAGA} | R Documentation |
SAGA Module Grid Calculus
Description
Perform Arithmetic Operations on Grids
Usage
rsaga.grid.calculus(in.grids, out.grid, formula, env = rsaga.env(), ...)
rsaga.linear.combination(
in.grids,
out.grid,
coef,
cf.digits = 16,
remove.zeros = FALSE,
remove.ones = TRUE,
env = rsaga.env(),
...
)
Arguments
in.grids |
input character vector: SAGA grid files (default file extension: |
out.grid |
output: grid file resulting from the cell-by-cell application of 'formula' to the grids. Existing files will be overwritten! |
formula |
character string of formula specifying the arithmetic operation to be performed on the |
env |
RSAGA geoprocessing environment, generated by a call to |
... |
optional arguments to be passed to |
coef |
numeric: coefficient vector to be used for the linear combination of the |
cf.digits |
integer: number of digits used when converting the |
remove.zeros |
logical: if |
remove.ones |
logical: if |
Details
The in.grids
are represented in the formula
by the letters a
(for in.grids[1]
), b
etc. Thus, if in.grids[1]
is Landsat TM channel 3 and in.grids[2]
is channel 4, the NDVI formula (TM3-TM4)/(TM3+TM4) can be represented by the character string "(a-b)/(a+b)"
(any spaces are removed) or the formula ~(a-b)/(a+b)
in the formula
argument.
In addition to +, -, *, and /, the following operators and functions are available for the formula
definition:
+ \hat{\ }
power
+ sin(a)
sine
+ cos(a)
cosine
+ tan(a)
tangent
+ asin(a)
arc sine
+ acos(a)
arc cosine
+ atan(a)
arc tangent
+ atan2(a,b)
arc tangent of b/a
+ abs(a)
absolute value
+ int(a)
convert to integer
+ sqr(a)
square
+ sqrt(a)
square root
+ ln(a)
natural logarithm
+ log(a)
base 10 logarithm
+ mod(a,b)
modulo
+ gt(a, b)
returns 1 if a greater b
+ lt(a, b)
returns 1 if a lower b
+ eq(a, b)
returns 1 if a equal b
+ ifelse(switch, x, y)
returns x if switch equals 1 else y
Using remove.zeros=FALSE
might have the side effect that no data areas in the grid with coefficient 0 are passed on to the results grid. (To be confirmed.)
Value
The type of object returned depends on the intern
argument passed to the rsaga.geoprocessor()
. For intern=FALSE
it is a numerical error code (0: success), or otherwise (the default) a character vector with the module's console output.
Author(s)
Alexander Brenning (R interface), Olaf Conrad (SAGA module)
See Also
local.function()
, focal.function()
, and multi.focal.function()
for a more flexible framework for combining grids or applying local and focal functions; rsaga.geoprocessor()
, rsaga.env()
Examples
## Not run:
# using SAGA grids:
# calculate the NDVI from Landsat TM bands 3 and 4:
rsaga.grid.calculus(c("tm3.sgrd","tm4.sgrd"), "ndvi.sgrd", ~(a-b)/(a+b))
# apply a linear regression equation to grids:
coefs = c(20,-0.6)
# maybe from a linear regression of mean annual air temperature (MAAT)
# against elevation - something like:
# coefs = coef( lm( maat ~ elevation ) )
rsaga.linear.combination("elevation.sgrd", "maat.sgrd", coefs)
# equivalent:
rsaga.grid.calculus("elevation.sgrd", "maat.sgrd", "20 - 0.6*a")
## End(Not run)