| distance_matrix | R Documentation |
Computes pairwise distances between geometries. For geographic (longlat)
coordinate systems, uses great circle distances in meters via sf::st_distance().
For projected coordinate systems, uses fast Euclidean distance in the CRS units
(typically meters).
distance_matrix(
x,
y = NULL,
type = c("euclidean", "manhattan"),
use_centroids = NULL
)
x |
An sf object (demand points for facility location, or areas for regionalization). |
y |
An sf object (facility locations). If NULL, computes distances within x. |
type |
Distance type: "euclidean" (default) or "manhattan". Note that for geographic CRS, only "euclidean" (great circle) distance is available. |
use_centroids |
Logical. If TRUE (default for polygons), use polygon centroids. |
A numeric matrix of distances. Rows correspond to x, columns to y. For geographic CRS, distances are in meters. For projected CRS, distances are in the CRS units (usually meters).
library(sf)
demand <- st_as_sf(data.frame(x = runif(10), y = runif(10)), coords = c("x", "y"))
facilities <- st_as_sf(data.frame(x = runif(5), y = runif(5)), coords = c("x", "y"))
d <- distance_matrix(demand, facilities)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.