ps_geodist: Geographic distance between sites

View source: R/ps_geodist.R

ps_geodistR Documentation

Geographic distance between sites

Description

Calculate pairwise geographic distances between occupied sites in a phylospatial object. The result is a dist object with the same dimensions and site ordering as ps_dissim(), making it straightforward to compare phylogenetic dissimilarity with geographic distance (e.g., for distance-decay analyses or Mantel tests).

Usage

ps_geodist(ps)

Arguments

ps

A phylospatial object with spatial data.

Details

For raster data, distances are computed between cell centroids. For polygon or line sf data, distances are computed between geometry centroids. Great-circle distances are used automatically when the data has a geographic (lon/lat) CRS; Euclidean distances are used for projected data or data without a CRS. Units are meters when a CRS is defined, or unitless coordinate distances otherwise.

Value

A pairwise geographic distance matrix of class dist, with one entry per pair of occupied sites. Units are meters when a CRS is defined, or raw coordinate units otherwise.

Examples


ps <- moss()
geo <- ps_geodist(ps)
phy <- ps_dissim(ps)

# distance-decay plot
plot(as.vector(geo), as.vector(phy),
     xlab = "Geographic distance (m)",
     ylab = "Phylogenetic dissimilarity",
     pch = ".", col = "#00000020")


phylospatial documentation built on April 4, 2026, 1:07 a.m.