Learn R Programming

gear (version 0.3.4)

geodist: 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 (longlat = FALSE) or great circle distance (longlat = FALSE) should be computed. The default is longlat = FALSE.

Value

A matrix of distances

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.

Examples

Run this code
# NOT RUN {
coords = matrix(runif(10), ncol = 2)
d = geodist(coords)
all.equal(d, as.matrix(dist(coords)), check.attributes = FALSE)
# }

Run the code above in your browser using DataLab