View source: R/extract_static_coords.R
extract_static_coords | R Documentation |
Explanatory variable data are extracted from static environmental rasters at record co-ordinate or across moving window matrix
extract_static_coords(
occ.data,
varnames,
extraction.method = "simple",
static.rasters,
moving.window.matrix,
GEE.math.fun
)
occ.data |
a data frame, with columns for occurrence record co-ordinates and dates with column names as follows; record longitude as "x", latitude as "y", and associated explanatory variable data. |
varnames |
a character string or vector, the unique names for each explanatory variable in order of layers in the SpatRaster. |
extraction.method |
a character string or vector, the methods to extract
data from SpatRaster using |
static.rasters |
a |
moving.window.matrix |
optional; a matrix of weights with an odd number
of sides, representing the spatial neighbourhood of cells (“moving
window”) to calculate |
GEE.math.fun |
optional; a character string, the mathematical function to compute across the specified spatial matrix for each record. |
Function to extract data from static rasters either at occurrence record co-ordinates or spatially buffered using a moving window matrix.
Note:
varnames
must be in the order of raster layers within the SpatRaster.
extraction.method
must be of length one to apply to all layers, or
length equal to the number of layers in static.rasters
.
Returns the occurrence data frame with added columns for extracted data.
Using the focal
function from terra
R package (Hijmans et al., 2022),
GEE.math.fun
is calculated across the spatial buffer area from the record
co-ordinate. The spatial buffer area used is specified by the argument
moving.window.matrix
, which dictates the neighbourhood of cells
surrounding the cell containing the occurrence record to include in this
calculation.
See function get_moving_window()
to generate appropriate
moving.window.matrix
.
GEE.math.fun
specifies the mathematical function to be calculated over the
spatial buffered area and temporal period. Options are limited to Google
Earth Engine ImageCollection Reducer functions
(https://developers.google.com/earth-engine/apidocs/) for which an
analogous R function is available. This includes: "allNonZero","anyNonZero",
"count", "first","firstNonNull", "last", "lastNonNull", "max","mean",
"median","min", "mode","product", "sampleStdDev", "sampleVariance",
"stdDev", "sum" and "variance".
Hijmans, R.J., Bivand, R., Forner, K., Ooms, J., Pebesma, E. and Sumner, M.D., 2022. Package ‘terra’. Maintainer: Vienna, Austria.
data("sample_explan_data")
random_cat_layer <- terra::rast(sample_extent_data)
random_cat_layer <- terra::setValues(random_cat_layer,
sample(0:10, terra::ncell(random_cat_layer),
replace = TRUE))
extract_static_coords(occ.data = sample_explan_data,
varnames = "random_cat_layer",
static.rasters = random_cat_layer)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.