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.
Arguments
- virtual_sample
A list output from
virtualspecies::sampleOccurrences(), containingsample.points, a data frame with columnsxandy, andoriginal.distribution.raster, aterra::SpatRasterobject.- raster_lyr
Optional. A
terra::SpatRasterfrom 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 theObservedcolumn.- ...
Any additional columns from
sample.pointsor 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.
See also
Other main:
add_coordinate_uncertainty(),
filter_observations(),
grid_designation(),
sample_observations(),
simulate_occurrences()
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)
)
} # }
