hav_dist: A Haversine Distance Function

View source: R/haversine_distance_function.R

hav_distR Documentation

A Haversine Distance Function

Description

This function computes the great circle distance between two points (long, lat). Computations default to kilometers (for the WGS84 ellipsoid).
This code was adapted from https://en.wikipedia.org/wiki/Great-circle_distance; https://en.wikipedia.org/wiki/Haversine_formula; and http://www.movable-type.co.uk/scripts/latlong.html See also, in the geosphere package https://cran.r-project.org/web/packages/geosphere/geosphere.pdf:
distm(p1, p2, fun = distVincentyEllipsoid) and distHaversine()

Usage

hav_dist(long1, lat1, long2, lat2, radius = 6371)

Arguments

long1

longitude for first point

lat1

latitude for first point

long2

longitude for second point

lat2

latitude for first point

radius

the radius of the earth; units of computed distance will be the same as the units of R. Dafaults to 6371 kilometers.

Examples

hav_dist(0,0,45,45)
distHaversine(c(0,0), c(45,45))/1000

JenC36/JACtools documentation built on Oct. 20, 2024, 8:05 a.m.