geodist {gear} | R Documentation |
Compute distance for geographic coordinates
Description
geodist
computes the distance between the
coordinates in coords1
and coords2
. If
coords2
isn't supplied, then the distances are
computed between the coordinates in coords1
alone.
Otherwise, the pairwise distances between then points in
coords1
and coords2
is computed. If
longlat = TRUE
, then the great circle distance is
computed.
Usage
geodist(coords1, coords2, longlat = FALSE)
Arguments
coords1 |
A two-dimensional matrix of coordinates. |
coords2 |
A two-dimensional matrix of coordinates. |
longlat |
A logical value indicating whether
Euclidean distance ( |
Details
The algorithm used when longlat = TRUE
is a C++
port of the C code written by Roger Bivand for
spDists
, which appears to be based on a
special case of the Vincenty formula with a slight
correction based on the WGS84 flattening constant. See
https://en.wikipedia.org/wiki/Great-circle_distance.
Value
A matrix of distances
Examples
coords = matrix(runif(10), ncol = 2)
d = geodist(coords)
all.equal(d, as.matrix(dist(coords)), check.attributes = FALSE)