Description Usage Arguments Details Author(s) See Also Examples

View source: R/distance_by_haversine.R

`distance_by_haversine`

is used when distances between latitude and
longitude-pairs need to be represented in metre or kilometre units. The
distances between two points is based on the Haversine Formula which is
approximate and is most appropriate when used for short-distance calculations.

1 2 | ```
distance_by_haversine(latitude, longitude, latitude_lag = NA,
longitude_lag = NA, unit = "metres", radius = 6371)
``` |

`latitude` |
A vector of latitude values in decimal degrees. |

`longitude` |
A vector of longitude values in decimal degrees. |

`latitude_lag` |
A vector of latitude values in decimal degrees. |

`longitude_lag` |
A vector of longitude values in decimal degrees. |

`unit` |
The unit of the returned distance values. Can be metres or kilometres. Metres is the default. |

`radius` |
The radius of the Earth in kilometres. The default value is 6371, but I have seen versions of similar functions which use slightly different values (plus or minus two or three kilometres) so this value can be altered. |

The Haversine Formula does not compensate for Earth's non-spherical shape, will overestimate distances in the polar regions but will underestimate distances near the equator. For more information see https://en.wikipedia.org/wiki/Haversine_formula

`distance_by_haversine`

is not a spatial function and does not have any
geographic library dependencies. If a spatial funcion is desired or distances
to/betwwen lines or polygons need to be calculated see
`sp_distance`

.

Stuart K. Grange

See `gDistance`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ```
## Not run:
# What is the distance between Oxford's Radcliffe Camera and Cliveden House
in Buckinghamshire?
# In metres
distance_by_haversine(51.753447, -1.254024, 51.558170, -0.688250)
44662.57
# In kilometres
distance_by_haversine(51.753447, -1.254024, 51.558170, -0.688250, "km")
44.66257
# or because we are in a locale with a different distance unit, in miles
distance_by_haversine(51.753447, -1.254024, 51.558170, -0.688250, "km") * 0.62
27.69079
# Data frame usage
# Distances of many air quality monitoring sites from the City of London
data_air$distance <- distance_by_haversine(
data_air$latitude, data_air$longitude, 51.513468, -0.089133, "km")
# Arrange by distance, closest at the top
data_air <- plyr::arrange(data_air, distance)
## End(Not run)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.