gcd: Distance between two points by Haversine, Spherical Law of...

View source: R/gcd.R

gcdR Documentation

Distance between two points by Haversine, Spherical Law of Cosines, or Vincenty inverse formula

Description

Calculates the geodesic distance between two points (or multiple pairs of points) specified by degrees (DD) latitude/longitude using Haversine formula (hf), Spherical Law of Cosines (slc) and Vincenty inverse formula for ellipsoids (vif)
Taken from http://www.r-bloggers.com/great-circle-distance-calculations-in-r/
Note these are not the most accurate method for long distances (e.g., >1000 km) nor the fastest.

Usage

gcd(frompoints, topoints, dfunc = "hf", units = "km")

Arguments

frompoints

Required matrix or data.frame of 2 columns, named lat and lon, with latitude and longitude(s) in degrees, one row per point.

topoints

Required matrix or data.frame of 2 columns, named lat and lon, with latitude and longitude(s) in degrees, one row per point.

dfunc

Character string "hf" for Haversine by default, or "slc" for Spherical Law of Cosines (and may add "vif" for Vincenty inverse formula but that is not implemented here). For "sp" algorithm (sp), see get.distances

units

Optional character variable specifying 'km' or 'miles', 'km' by default.

Details

*** frompoints and topoints must have same number of rows, defining all pairs of points. Alternatively can define a single point while topoints defines a series of points, or vice versa. Taken from http://www.r-bloggers.com/great-circle-distance-calculations-in-r/ but use pmin instead of min to vectorize it to handle at least pairs, and parameters changed to keep lat/lon as a matrix or data.frame rather than 2 separate vectors.

Value

Distance in kilometers by default, or in miles if units='miles'

See Also

convert, gcd, get.distances, get.distances.all


ejanalysis/proxistat documentation built on April 2, 2024, 10:13 a.m.