geodist_vec | R Documentation |
An alternative interface to the main geodist function that directly accepts inputs as individual vectors of coordinates, rather than the matrix or 'data.frame' inputs of the main function. This interface is provided for cases where computational efficiency is important, and will generally provide faster results than the main function.
geodist_vec(
x1,
y1,
x2,
y2,
paired = FALSE,
sequential = FALSE,
pad = FALSE,
measure = "cheap",
quiet = FALSE
)
x1 |
Numeric vector of longitude coordinates |
y1 |
Numeric vector of latitude coordinates |
x2 |
Optional second numeric vector of longitude coordinates |
y2 |
Optional second numeric vector of latitude coordinates |
paired |
If |
sequential |
If |
pad |
If |
measure |
One of "haversine" "vincenty", "geodesic", or "cheap" specifying desired method of geodesic distance calculation; see Notes. |
quiet |
If |
If only (x1, y1)
are passed and sequential = FALSE
, a
square symmetric matrix containing distances between all items in (x1,
y1)
; If only (x1, y1)
are passed and sequential = TRUE
, a
vector of sequential distances between matching elements of (x1, y1)
;
otherwise if (x2, y2)
are passed, a matrix of lenght(x1) ==
length(y1)
rows and length(x2) == length(y2)
columns.
measure = "cheap"
denotes the mapbox cheap ruler
https://github.com/mapbox/cheap-ruler-cpp; measure = "geodesic"
denotes the very accurate geodesic methods given in Karney (2013)
"Algorithms for geodesics" J Geod 87:43-55, and as provided by the
'st_dist()' function from the sf package.
n <- 50
# Default "cheap" distance measure is only accurate for short distances:
x1 <- -1 + 2 * runif (n, -0.1, 0.1)
y1 <- -1 + 2 * runif (n, -0.1, 0.1)
d0 <- geodist_vec (x1, y1) # A 50-by-50 matrix
d2 <- geodist_vec (x1, y1, sequential = TRUE) # Vector of length 49
d2 <- geodist_vec (x1, y1, sequential = TRUE, pad = TRUE) # length 50
x2 <- -10 + 20 * runif (2 * n, -0.1, 0.1)
y2 <- -10 + 20 * runif (2 * n, -0.1, 0.1)
d1 <- geodist_vec (x1, y1, x2, y2) # A 50-by-100 matrix
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.