math-generics.Rd
Standard mathematical methods for computations with SpatRaster objects. Computations are local (applied on a cell by cell basis). If multiple SpatRaster objects are used, these must have the same extent and resolution. These have been implemented:
abs, sign, sqrt, ceiling, floor, trunc, cummax, cummin, cumprod, cumsum, log, log10, log2, log1p, acos, acosh, asin, asinh, atan, atanh, exp, expm1, cos, cosh, sin, sinh, tan, tanh, round, signif
Instead of directly calling these methods, you can also provide their name to the math
method. This is useful if you want to provide an output filename.
The following methods have been implemented for SpatExtent
: round, floor, ceiling
round
has also been implemented for SpatVector
, to round the coordinates of the geometries.
See app
to use mathematical functions not implemented by the package, and Arith-methods
for arithmetical operations. Use roll
for rolling functions.
SpatRaster
a positive or complex number: the base with respect to which logarithms are computed
Number of digits for rounding
character. Math function name
character. Output filename
logical. If TRUE
, filename
is overwritten
additional arguments for writing files as in writeRaster
SpatRaster or SpatExtent
r1 <- rast(ncols=10, nrows=10)
v <- runif(ncell(r1))
v[10:20] <- NA
values(r1) <- v
r2 <- rast(r1)
values(r2) <- 1:ncell(r2) / ncell(r2)
r <- c(r1, r2)
s <- sqrt(r)
# same as
math(r, "sqrt")
#> class : SpatRaster
#> dimensions : 10, 10, 2 (nrow, ncol, nlyr)
#> resolution : 36, 18 (x, y)
#> extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84
#> source(s) : memory
#> names : lyr.1, lyr.1
#> min values : 0.1272139, 0.1
#> max values : 0.9975409, 1.0
round(s, 1)
#> class : SpatRaster
#> dimensions : 10, 10, 2 (nrow, ncol, nlyr)
#> resolution : 36, 18 (x, y)
#> extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84
#> source(s) : memory
#> names : lyr.1, lyr.1
#> min values : 0.1, 0.1
#> max values : 1.0, 1.0
cumsum(r)
#> class : SpatRaster
#> dimensions : 10, 10, 2 (nrow, ncol, nlyr)
#> resolution : 36, 18 (x, y)
#> extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84
#> source(s) : memory
#> names : lyr.1, lyr.1
#> min values : 0.01618339, 0.1201457
#> max values : 0.99508793, 1.8533974