Skip to contents

Converts virtual species samples generated with the virtualspecies package into a spatial (sf) object compatible with gcube workflows. Optionally extracts values from raster layers at the sample locations.

Usage

virtualsample_to_sf(virtual_sample, raster_lyr = NULL)

Arguments

virtual_sample

A list output from virtualspecies::sampleOccurrences(), containing sample.points, a data frame with columns x and y, and original.distribution.raster, a terra::SpatRaster object.

raster_lyr

Optional. A terra::SpatRaster from which to extract values at sample locations. For example, habitat suitability or probability of occurrence rasters.

Value

An sf object (point geometry) with the following columns:

id

A character ID for each sample point (based on row names of sample.points).

observed

Logical value indicating if the sample was observed (TRUE) or a non-detection (FALSE), based on the Observed column.

...

Any additional columns from sample.points or extracted from the raster layer(s).

geometry

Point geometry in the coordinate reference system of the original distribution raster.

Details

This function is typically used as the first step after sampling from a virtual species distribution before applying functions like filter_observations(), add_coordinate_uncertainty(), and grid_designation(). See the tutorial "Create occurrence cubes for virtual species" for a full workflow example.

If raster layers are provided through raster_lyr, the values at each point are extracted using terra::extract() and appended to the output.

Examples

if (FALSE) { # \dontrun{
# After generating a virtual species and sampling occurrences
# with virtualspecies::sampleOccurrences()
virtualsample_to_sf(virtual_sample)

# Optionally extract suitability and occurrence probability
virtualsample_to_sf(
  virtual_sample,
  raster_lyr = c(virtual_species$suitab.raster,
                 virtual_species$probability.of.occurrence)
)
} # }