gcd | R Documentation |
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.
gcd(frompoints, topoints, dfunc = "hf", units = "km")
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 |
units |
Optional character variable specifying 'km' or 'miles', 'km' by default. |
*** 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.
Distance in kilometers by default, or in miles if units='miles'
convert
, gcd
, get.distances
, get.distances.all
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.