extract_static_coords {dynamicSDM}R Documentation

Extract explanatory variables from static rasters

Description

Explanatory variable data are extracted from static environmental rasters at record co-ordinate or across moving window matrix

Usage

extract_static_coords(
  occ.data,
  varnames,
  extraction.method = "simple",
  static.rasters,
  moving.window.matrix,
  GEE.math.fun
)

Arguments

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 terra package extract function. One of simple or bilinear. If simple values for the cell a point falls in are returned. If bilinear the returned values are interpolated from the values of the four nearest raster cells.

static.rasters

a SpatRaster containing one or more SpatRaster layers to extract data from.

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 across from record co-ordinate. See details for more information.

GEE.math.fun

optional; a character string, the mathematical function to compute across the specified spatial matrix for each record.

Details

Function to extract data from static rasters either at occurrence record co-ordinates or spatially buffered using a moving window matrix.

Note:

Value

Returns the occurrence data frame with added columns for extracted data.

Spatial buffering (optional)

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.

Mathematical function

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".

References

Hijmans, R.J., Bivand, R., Forner, K., Ooms, J., Pebesma, E. and Sumner, M.D., 2022. Package ‘terra’. Maintainer: Vienna, Austria.

Examples


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)



[Package dynamicSDM version 1.3.4 Index]