Learn R Programming

RavenR (version 2.2.0)

rvn_dist_lonlat: Calculate distance from long/lat

Description

Calculates distance between points based on a set of long/lat coordinates.

Usage

rvn_dist_lonlat(p1, p2, method = "haversine", r = 6378137)

Value

a vector of calculated distances (length of vector based on input)

Arguments

p1

longitude/latitude of point(s); can be a vector of two numbers, or a matrix of 2 columns (long/lat).

p2

second point in same format as p1

method

calculation method as either haversine (default) or vincentysphere

r

radius of the Earth in metres (default 6378137)

Details

Calculates distance in metres based on the longitude and latitude of two or more sets of points.

The function uses either the Haversine or Vincenty Sphere methods to calculate the distances.

Examples

Run this code
# calculate distance from Engineering 2 (p1) to Graduate House (p2) at the University of Waterloo
p1 <- c(-80.5402891965711,43.47088594350457)
p2 <- c(-80.54096577853629,43.46976096704924)
rvn_dist_lonlat(p1, p2)

# distance from University of Waterloo to Windsor
p2 <- c(-83.02099905916948,42.283371378771555)
rvn_dist_lonlat(p1, p2)

Run the code above in your browser using DataLab