rsaga.grid.calculus: SAGA Module Grid Calculus

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Perform Arithmetic Operations on Grids

Usage

1
2
3
4
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 (the default), factors equal to 1 (after rounding to cf.digits digits) will be removed from the formula

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.)

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## 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)

RSAGA documentation built on May 2, 2019, 11:01 a.m.