
Function to extract point values directly from a SpatRaster
Source:R/utils-spatial.R
get_rastervalue.Rd
This function simply extracts the values from a provided
SpatRaster
, SpatRasterDataset
or SpatRasterCollection
object. For
points where or NA
values were extracted a small buffer is applied to try and
obtain the remaining values.
Arguments
- coords
A
data.frame
,matrix
orsf
object.- env
A
SpatRaster
object with the provided predictors.- ngb_fill
logical
on whether cells should be interpolated from neighbouring values.- rm.na
logical
parameter which - if set - removes all rows with a missing data point (NA
) from the result.
Value
A data.frame
with the extracted covariate data from each provided
data point.
Details
It is essentially a wrapper for terra::extract
.
Examples
# Dummy raster:
r <- terra::rast(nrows = 10, ncols = 10, res = 0.05, xmin = -1.5, xmax = 1.5,
ymin = -1.5, ymax = 1.5, vals = rnorm(3600,mean = .5,sd = .1))
# (dummy points)
pp <- terra::spatSample(r,20,as.points = TRUE) |> sf::st_as_sf()
# Extract values
vals <- get_rastervalue(pp, r)
head(vals)
#> ID lyr.1 x y
#> 1 1 0.2994830 -1.025 0.125
#> 2 2 0.3001460 1.425 -1.075
#> 3 3 0.7130464 1.325 0.475
#> 4 4 0.5830595 1.225 0.375
#> 5 5 0.6122107 -0.575 -0.475
#> 6 6 0.3984823 -1.025 1.075