Description Usage Arguments Value Examples
Calculates distances from latitudes and longitudes. Math is done such that passing vectors for each parameter is allowed provided that vectors are the same length for corresponding arguments. Returns a vector of distances if location1 or location2 is of length 1, or a distance matrix otherwise. If only one location is specified, a distance matrix between locations is calculated. Distance is based on the haversine formula.
1 2 |
long1 |
longitude of location 1 |
lat1 |
latitude of location 1 |
long2 |
longitude of location 2 (optional) |
lat2 |
latitude of location 2 (optional) |
labels |
labels assigned to location 1 (for dist matrix) |
labels2 |
labels assigned to location 2 (for dist matrix; optional) |
R |
radius of the earth (using the same as |
A vector of distances if location1 or location2 is of length 1, or a distance matrix otherwise.
1 2 3 4 5 6 7 8 9 10 11 | #compute distance from one point to another
geodist(-64.35984, 45.09176, -63.57532, 44.64886)
#compute a distance matrix
locs <- c("wolfville, ns", "halifax, ns", "yarmouth, ns", "sydney, ns", "amherst, ns")
lons <- c(-64.35984, -63.57532, -66.11738, -60.19422, -64.21672)
lats <- c(45.09176, 44.64886, 43.83746, 46.13679, 45.81667)
geodist(lons, lats, labels=locs)
#compute distances from one point to a vector of distances
geodist(-64.45665, 44.73701, lons, lats)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.