| GeoDistances | R Documentation |
Compute a full distance matrix between coordinates in 2D or 3D, using Euclidean,
Chordal, or Geodesic distance. The computation is done in C for efficiency,
with parameters passed from R via dotCall64.
GeoDistances(coordx = NULL, coordy = NULL, coordz = NULL,
distance = c("Eucl", "Chor", "Geod"), radius = 1)
coordx |
A numeric matrix of coordinates. Must have 2 or 3 columns
(for 2D or 3D) (if coordy and coordz are not provided). Otherwise
coordinates can be given via
|
coordy |
Optional numeric vector of coordinates. |
coordz |
Optional numeric vector of coordinates (for 3D Euclidean). |
distance |
Type of distance to compute:
|
radius |
Radius of the sphere for geodesic or chordal distances. Defaults to 1. Use Earth radius (e.g., 6371 Km) for geographic distances. |
Euclidean distance: straight-line distance in 2D or 3D space.
Chordal distance: Euclidean distance between points projected on the unit sphere, scaled by the given radius.
Geodesic distance: shortest path along the surface of a sphere of
radius radius.
A symmetric numeric matrix of size n x n, where n is the number
of points. Each entry contains the distance between the corresponding pair
of coordinates.
# Example with Euclidean distance
coords <- cbind(c(0, 10), c(0, 10))
GeoDistances(coords, distance = "Eucl")
# Example with geodesic distance (approx distance between Rome and New York)
rome <- c(12.4964, 41.9028) #
ny <- c(-74.0060, 40.7128)
coords <- rbind(rome, ny)
GeoDistances(coords, distance = "Geod", radius = 6371)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.