geoDist: Straight-line distance between two sets of coordinates

Description Usage Arguments Details Value Warning Author(s) Examples

Description

Calculates the geographic distance (in kilometers) between a reference point and a set of coordinates using the Haversine formula (great-circle distance).

Usage

1
geoDist(ref, coords)

Arguments

ref

The reference Latitude and Longitude coordinates used as the 'starting point' for the geographic distance measure.

coords

The Latitude and Longitude coordinates representing the 'end point' for the geographic distance measure.

Details

More than one value can be supplied to the coords data frame. See example below.

Value

A numeric value in kilometers between the reference point and each point in coord

Warning

It is assumed the coordinates will have column names matching "Latitude" and "Longitude". If these column names are not found the function will fail. Use colnames(x) <- c("Latitude", "Longitude") to change the column names, where x is the data frame

Author(s)

P. A. Harrison

Examples

 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
27
28
29
# set up the 'ref' data frame
tmp0 <- data.frame(Longitude = 147.4686, Latitude = -42.008)

# set up the 'coord' data frame
tmp1 <- data.frame(Longitude = 147.1541, Latitude = -41.8339)

# run the function
PUCA::geoDist(tmp0, tmp1)
#   geoDist
# 1   32.47

#not ran
#set up red and coord in same data frame
tmp <- rbind(tmp0, tmp1)

#run the function
#PUCA::geoDist(tmp[1,], tmp[2,])
#   geoDist
# 1   32.47

# set up the 'coord' data frame with more than one point
tmp1 <- data.frame(Longitude = c(147.1541, 147.457063), Latitude = c(-41.8339, -41.980778))

# run the function
geoDist(tmp0, tmp1)

#   geoDist
# 1   32.47
# 2    3.18

peteraharrison/PUCA documentation built on Sept. 16, 2019, 7:56 a.m.