terra (version 0.3-7)

math: Mathematical operations with SpatRaster objects

Description

Standard arithmetic operators for computations with SpatRaster objects and numeric values. The following operators and methods are available for SpatRaster:

Arith: +, -, *, /, ^, %%, %/%

Compare: ==, !=, >, <, <=, >=

Summary: "max", "min", "range", "prod", "sum", "any", "all"

Math: "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"

Math2: "round", "signif"

If multiple SpatRaster objects are used, these must have the same extent and resolution. Operators are applied on a cell by cell basis.

For SpatExtent the following methods have been implemented: "round", "floor", "ceil", "=="

Arguments

Value

SpatRaster

Examples

Run this code
# NOT RUN {
r1 <- rast(ncols=10, nrows=10)
values(r1) <- runif(ncell(r1))
r2 <- rast(r1)
values(r2) <- 1:ncell(r2) / ncell(r2)
r3 <- r1 + r2
r2 <- r1 / 10
r3 <- r1 * (r2 - 1 / r2)


b <- c(r1, r2, r3)
b2 <- b * 10
s <- sqrt(b2)
round(s, 1)
# }

Run the code above in your browser using DataCamp Workspace