rsaga.grid.calculus {RSAGA} | R Documentation |
Perform Arithmetic Operations on Grids
rsaga.grid.calculus(in.grids, out.grid, formula, ...) rsaga.linear.combination(in.grids, out.grid, coef, cf.digits = 16, remove.zeros = FALSE, remove.ones = TRUE, ...)
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. |
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 coef ficients 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 (default), factors
equal to 1 (after rounding to cf.digits digits)
will be removed from the formula |
... |
optional arguments to be passed to rsaga.geoprocessor ,
including the env RSAGA geoprocessing environment |
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:
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.)
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 (default)
a character vector with the module's console output.
This function uses module 1 in the SAGA library grid_calculus
.
Alexander Brenning (R interface), Olaf Conrad (SAGA module)
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
## 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)