View source: R/info_utilities.R
get_gcdist | R Documentation |
Get the great circle distance between WGS84 lat/long points
get_gcdist(pt1 = NULL, pt2 = NULL, units = c("m", "km", "rads"), simple = TRUE)
pt1 |
'sf' object with point geometry, 'sfc_POINT' object, 'sfg' point, data frame or matrix. |
pt2 |
'sf' object with point geometry, 'sfc_POINT' object, 'sfg' point, data frame or matrix. |
units |
whether to return the great circle distance in meters, kilometers, or radians. |
simple |
whether to return a numeric vector of distances or a 'data.frame' containing start and end coordinates as well as distance. |
Numeric vector of point to point distances, or data frame of origin and destination coordinates accompanied by their distances.
This functionality also exists in R packages sp
, sf
,
geosphere
and fields
. H3's version appears to return slightly
shorter distances than most other implementations, but is included here
for completeness.
# distance between Brisbane and Melbourne bne <- c(153.028, -27.468) mlb <- c(144.963, -37.814) get_gcdist(bne, mlb, 'km')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.