Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

selectRange

Select the values of a range of layers, as specified by cell values in another SpatRaster


Description

Use a single layer SpatRaster to select cell values from different layers in a multi-layer SpatRaster. The values of the SpatRaster to select layers (y) should be whole numbers between 1 and nlyr(x) (values outside this range are ignored).

See rapp for applying af function to a range of variable size.

See extract for extraction of values by cell, point, or otherwise.

Usage

## S4 method for signature 'SpatRaster'
selectRange(x, y, z=1, repint=0, filename="", ...)

Arguments

x

SpatRaster

y

SpatRaster. Cell values must be positive integers. They indicate the first layer to select for each cell

z

positive integer. The number of layers to select

repint

integer > 1 and < nlyr(x) allowing for repeated selection at a fixed interval. For example, if x has 36 layers, and the value of a cell in y=2 and repint = 12, the values for layers 2, 14 and 26 are returned

filename

character. Output filename

...

additional arguments for writing files as in writeRaster

Value

SpatRaster

See Also

Examples

r <- rast(ncol=10, nrow=10)
values(r) <- 1
s <- c(r, r+2, r+5)
s <- c(s, s)
set.seed(1)
values(r) <- sample(3, ncell(r), replace=TRUE)
x <- selectRange(s, r)

x <- selectRange(s, r, 3)

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.