Learn R Programming

pegas (version 1.3)

geod: Geodesic Distances

Description

This function calculates geodesic (or great-circle) distances between pairs of points with their longitudes and latitudes given in (decimal) degrees.

Usage

geod(lon, lat = NULL, R = 6371)

Value

a numeric symmetric matrix with the distances between pairs of points in kilometres.

Arguments

lon

either a vector of numeric values with the longitudes in degrees, or, if lat = NULL, a matrix giving the longitudes (first column) and the latitudes (second column).

lat

a vector with the latitudes.

R

the mean radius of the Earth (see details).

Author

Emmanuel Paradis

Details

The default value of R is the mean radius of the Earth which is slightly smaller than the radius at the equator (6378.1 km).

References

https://en.wikipedia.org/wiki/Great-circle_distance

https://en.wikipedia.org/wiki/Earth

See Also

geoTrans, as.dist

Examples

Run this code
## the distance between 0N 0E and 0N 180E...
geod(c(0, 180), c(0, 0)) # ~ 20015.09 km
## ... the same using the radius of the Earth at the equator:
geod(c(0, 180), c(0, 0), 6378.1) # ~ 20037.39 km
## The same comparison for two points 5 degrees apart:
geod(c(0, 5), c(0, 0)) # ~ 555.9746 km
geod(c(0, 5), c(0, 0), 6378.1) # ~ 556.5942 km

Run the code above in your browser using DataLab