| distances | R Documentation |
Pre-compute pairwise distances between sites for reuse across multiple
spacc() calls. Supports sf objects with accurate geodesic distances
for global-scale studies.
distances(x, method = NULL, fun = NULL, which = NULL)
x |
Site locations. Can be:
|
method |
Character. Distance method:
|
fun |
Optional custom distance function. Must take two coordinate
vectors (x, y) and return a distance matrix. Overrides |
which |
For sf objects, column name containing the geometry. Default uses active geometry. |
For continental and global-scale studies, use sf objects with geographic CRS (e.g., EPSG:4326). The function will automatically use accurate geodesic distances via the S2 spherical geometry library.
For smaller study areas with projected coordinates (UTM, etc.), Euclidean distance is appropriate and faster.
An object of class spacc_dist containing the distance matrix
with coordinates stored as an attribute.
coords <- data.frame(x = runif(50), y = runif(50))
d <- distances(coords)
# Reuse for multiple analyses
species <- matrix(rbinom(50 * 30, 1, 0.3), nrow = 50)
sac <- spacc(species, d)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.