Learn R Programming

RSAGA (version 0.94-5)

rsaga.grid.calculus: 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: .sgrd)
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 in.grids (see Details); if this is a formula, only the right hand side will be used.
env
RSAGA geoprocessing environment, generated by a call to rsaga.env
...
optional arguments to be passed to rsaga.geoprocessor
coef
numeric: coefficient vector to be used for the linear combination of the in.grids. If coef as one more element than in.grids, the first one will be interpreted as an intercept.
cf.digits
integer: number of digits used when converting the coefficients to character strings (trailing zeros will be removed)
remove.zeros
logical: if TRUE, terms (grids) with coefficient (numerically) equal to zero (after rounding to cf.digits digits) will be removed from the formula
remove.ones
logical: if TRUE (th edefault), factors equal to 1 (after rounding to cf.digits digits) will be removed from the formula

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.

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:

  • $^$ 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.)

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

Run this code
## 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)

Run the code above in your browser using DataLab