GeoDistances: Compute Distance Matrices (Euclidean, Chordal, or Geodesic)

View source: R/GeoDistances.R

GeoDistancesR Documentation

Compute Distance Matrices (Euclidean, Chordal, or Geodesic)

Description

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.

Usage

GeoDistances(coordx = NULL, coordy = NULL, coordz = NULL,
             distance = c("Eucl", "Chor", "Geod"), radius = 1)

Arguments

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 coordx, coordy, and optionally coordz.

coordy

Optional numeric vector of coordinates.

coordz

Optional numeric vector of coordinates (for 3D Euclidean).

distance

Type of distance to compute: "Eucl" for Euclidean, "Chor" for chordal, "Geod" for geodesic.

radius

Radius of the sphere for geodesic or chordal distances. Defaults to 1. Use Earth radius (e.g., 6371 Km) for geographic distances.

Details

  • 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.

Value

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.

Examples

# 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)

GeoModels documentation built on Nov. 25, 2025, 1:06 a.m.