Learn R Programming

terra (version 1.5-12)

Arith-methods: Arithmetic

Description

Standard arithmetic operators for computations with SpatRasters. Computations are local (applied on a cell by cell basis). If multiple SpatRaster objects are used, these must have the same geometry (extent and resolution). These operators have been implemented:

+, -, *, /, ^, %%, %/%

The following methods have been implemented for SpatExtent:

for (SpatExtent, SpatExtent): +, -, and for (SpatExtent, numeric): +, -, *, /, %%

Arguments

Value

SpatRaster or SpatExtent

seealso

ifel to conveniently combine operations and Math-methods or app to use mathematical functions not implemented by the package.

Examples

Run this code
# NOT RUN {
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)
r3 <- r1 + r2
r2 <- r1 / 10
r3 <- r1 * (r2 - 1 / r2)

b <- c(r1, r2, r3)
b2 <- b * 10

### SpatExtent methods
x <- ext(0.1, 2.2, 0, 3)
y <- ext(-2, 1, -2,2)
# union
x + y
# intersection
x * y

e <- x 
# }
# NOT RUN {
<!-- %% 2 -->
# }
# NOT RUN {
e
e * 2
e / 2
e + 1
e - 1
# }

Run the code above in your browser using DataLab