Learn R Programming

oce (version 0.8-3)

geodDist: Geodesic distance on earth

Description

Compute geodesic distance on surface of earth.

Usage

geodDist(lat1, lon1, lat2, lon2, alongPath=FALSE)

Arguments

lat1
latitude or a vector of latitudes, or a section object, from which latitude and longitude are extracted and used instead of the next three arguments
lon1
longitude or vector of longitudes (ignored if lat1 is a section object)
lat2
optional latitude or vector of latitudes (ignored if alongPath=TRUE
lon2
optional longitude or vector of longitudes (ignored if alongPath=TRUE
alongPath
boolean indicating whether to compute distance along the path, as opposed to distance from the reference point. If alongPath=TRUE, any values provided for lat2 and lon2 will be ignored.

Value

  • Vector of distances in kilometres.

Details

This calculates distance between points on the earth, measured along the surface. The method involves the solution of the geodetic inverse problem, using T. Vincenty's modification of Rainsford's method with Helmert's elliptical terms.

The function may be used in several different ways.

Case 1: lat1 is a section object. The values of lon1, lat2, and lon2 arguments are ignored, and the behaviour depends on the value of the alongPath argument. If alongPath=FALSE, the return value contains the geodetic distances of each station from the first one. If alongPath=TRUE, the return value is the geodetic distance along the path connecting the stations, in the order in which they are stored in the section.

Case 2: lat1 is a vector. If lat2 and lon2 are not given, then the return value is a vector containing the distances of each point from the first one, or the distancce along the path connecting the points, according to the value of alongPath. On the other hand, if if lat2 and lon2 are specified, then the return result depends on the length of these arguments. If they are each of length 1, then they are taken as a reference point, from which the distances to lat1 and lon1 are calculated (ignoring the value of alongPath). However, if they are of the same length as lat1 and lon1, then the return value is the distance between corresponding (lat1,lon1) and (lat2,lon2) values.

References

T. Vincenty, "Direct and Inverse Solutions of Ellipsoid on the Ellipsoid with Application of Nested Equations", Survey Review, April 1975. (As of early 2009, this document is available at http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf.)

See Also

geodXy

Examples

Run this code
library(oce)
km <- geodDist(45, 100, 46, 100)/1000 
data(section)
geodDist(section)
geodDist(section, alongPath=TRUE)

Run the code above in your browser using DataLab