geodist: Calculate geographic distances

Description Usage Arguments Value Examples

Description

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.

Usage

1
2
geodist(long1, lat1, long2 = NULL, lat2 = NULL, labels = NULL,
  labels2 = NULL, R = 6378137)

Arguments

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 geosphere package)

Value

A vector of distances if location1 or location2 is of length 1, or a distance matrix otherwise.

Examples

 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)

paleolimbot/rfuncs documentation built on May 24, 2019, 6:13 p.m.