Skip to contents

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.

Usage

get_rastervalue(coords, env, ngb_fill = TRUE, rm.na = FALSE)

Arguments

coords

A data.frame, matrix or sf 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.6782599  1.225 -1.175
#> 2  2 0.6420574 -0.225  0.925
#> 3  3 0.5397701  0.075 -1.425
#> 4  4 0.4993814  0.975  0.775
#> 5  5 0.5545246  0.175  1.275
#> 6  6 0.4226162  0.625  0.625