Aggregate Site Data Along Coarser Spatial Grid
Source:R/fb_aggregate_site_data.R
fb_aggregate_site_data.Rd
This function helps aggregating site data along a coarser grid. The idea is that you have any type of data at the site scale (diversity metrics, environmental data, etc.) but you would like to work on it at a coarser scale, or you want to visualize it at that scale. This function helps you do exactly that.
Arguments
- site_locations
an
sf
object with the spatial geometries of sites. NOTE: the first column should be named"site"
and indicate site names.- site_data
a
matrix
ordata.frame
containing values per sites to aggregate along the provided grid. Can have one or several columns (variables to aggregate). The first column must contain sites names as provided in the example datasetsite_locations
.- agg_grid
a
SpatRaster
object (packageterra
). A raster of one single layer, that defines the grid along which to aggregate.- fun
the function used to aggregate points values when there are multiple points in one cell. Default is
mean
.
Examples
library("funbiogeo")
data("site_locations")
data("site_species")
## Import grid ----
tavg <- system.file("extdata", "annual_mean_temp.tif", package = "funbiogeo")
tavg <- terra::rast(tavg)
## Rasterize 3 first species counts ----
fb_aggregate_site_data(site_locations, site_species[, 1:4], tavg, fun = sum)
#> class : SpatRaster
#> dimensions : 290, 405, 3 (nrow, ncol, nlyr)
#> resolution : 0.08333333, 0.08333333 (x, y)
#> extent : -10.5, 23.25, 35.83333, 60 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> varnames : annual_mean_temp
#> annual_mean_temp
#> annual_mean_temp
#> names : sp_001, sp_002, sp_003
#> min values : 0, 0, 0
#> max values : 1, 1, 1