
Retrieve, crop, resample, and link environmental rasters to sampling sites
Source:R/get_enviro_data.R
get_enviro_data.Rd
get_enviro_data()
automates six steps:
AOI build – buffers the convex hull of all input points.
Raster acquisition – downloads or loads a multi-layer stack (WorldClim, SoilGrids, footprint, population, or user-supplied).
Cropping – trims the stack to the buffered AOI.
Optional resampling – resamples the cropped stack to a user-defined grid resolution.
Extraction & gap fill – pulls raster values at each site and linearly interpolates isolated NAs.
Assembly – returns a tidy site × environment table plus the cropped (and resampled) raster and an
sf
layer of sites.
Usage
get_enviro_data(
data,
buffer_km = 10,
source = "geodata",
var = "bio",
res = 2.5,
grid_r = NULL,
path = "data/",
year = NULL,
depth = NULL,
stat = "mean",
model = NULL,
ssp = NULL,
time = NULL,
sp_cols = NULL,
ext_cols = NULL
)
Arguments
- data
Data frame of spatial points; must include lon/lat columns such as
"x","y"
or"centroid_lon","centroid_lat"
.- buffer_km
Buffer width (km) for the AOI. Default 10.
- source
"geodata"
(default) to fetch layers via geodata or"local"
to supply a localSpatRaster
or file path.- var
Raster product to download (see details) or ignored when
source = "local"
.- res
Resolution (arc-min) for WorldClim/WorldPop layers (geodata).
- grid_r
Optional grid resolution (in same CRS units) to which the cropped raster is resampled before extraction. If
NULL
, no resampling is performed.- path
Cache folder for downloaded rasters (created if absent).
- year,
model, ssp, time Optional arguments for time-stamped products (human footprint, population, CMIP6, etc.).
- depth,
stat Arguments passed to
geodata::soil_world()
.- sp_cols
Columns to drop from the final table (e.g. a large species matrix). Accepts names or numeric indices relative to
data
.- ext_cols
Columns to append verbatim (e.g.
"obs_sum","spp_rich"
).