Skip to contents

Extract Raster Values at Location of Sites

Usage

fb_get_environment(site_locations, environment_raster)

Arguments

site_locations

an sf object with the spatial geometries of sites. NOTE: the first column should be named "site" and indicate site names.

environment_raster

a SpatRaster object (package terra). A single or multi-layers environmental raster.

Value

A data.frame with average environmental values (columns) per site (rows), with the first column being "site" indicating site names.

Examples

library("funbiogeo")

data("site_locations")

## Import climate rasters ----
prec <- system.file("extdata", "annual_tot_prec.tif", package = "funbiogeo")
tavg <- system.file("extdata", "annual_mean_temp.tif", package = "funbiogeo")

layers <- terra::rast(c(tavg, prec))

fb_get_environment(head(site_locations), layers)
#>   site annual_mean_temp annual_tot_prec
#> 1    1        6.6755822       2480.2222
#> 2    2        1.6836227       1994.0000
#> 3    3        0.6628264       1384.5000
#> 4    4        1.4940648       1033.4444
#> 5    5        2.6325313        945.3611
#> 6    6        3.0806597        975.2778