Package 'hans'

Title: Haversines are not Slow
Description: The haversine is a function used to calculate the distance between a pair of latitude and longitude points while accounting for the assumption that the points are on a spherical globe. This package provides a fast, dataframe compatible, haversine function. For the first publication on the haversine calculation see Joseph de Mendoza y RĂ­os (1795) <https://books.google.cat/books?id=030t0OqlX2AC> (In Spanish).
Authors: Alex Hallam [aut, cre]
Maintainer: Alex Hallam <[email protected]>
License: MIT + file LICENSE
Version: 0.1
Built: 2024-12-07 06:32:20 UTC
Source: CRAN

Help Index


Calculate the haversine distance in kilometers given lat/lon pairs

Description

Calculate the haversine distance in kilometers given lat/lon pairs

Usage

haversine(lat1, lon1, lat2, lon2)

Arguments

lat1

A vector of latitudes

lon1

A vector of longitudes

lat2

A vector of latitudes

lon2

A vector of longitudes

Value

a vector of distances in kilometers

Examples

# simple haversine calculation 
lon1 <- runif(-160, -60, n = 10e6)
lat1 <- runif(40, 60, n = 10e6)
lon2 <- runif(-160, -60, n = 10e6)
lat2 <- runif(40, 60, n = 10e6)
df <- data.frame(lat1, lon1, lat2, lon2)
df$havers <- haversine(df$lat1, df$lon1, df$lat2, df$lon2)