geodist_min | R Documentation |
Convert two rectangular objects containing lon-lat coordinates into an index vector of the elements in the second matrix corresponding to the minimal distance to each element of the first matrix.
geodist_min(x, y, measure = "cheap", quiet = FALSE)
x |
Rectangular object (matrix, |
y |
Second rectangular object to be search for minimal distance to each row in the first object. |
measure |
One of "haversine" "vincenty", "geodesic", or "cheap" specifying desired method of geodesic distance calculation; see Notes. |
quiet |
If |
A integer index vector indexing elements of 'y' corresponding to minimal distances to each element of 'x'. The length of this vector is equal to the number of rows in 'x'.
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:
x <- cbind (runif (n, -0.1, 0.1), runif (n, -0.1, 0.1))
y <- cbind (runif (2 * n, -0.1, 0.1), runif (2 * n, -0.1, 0.1))
colnames (x) <- colnames (y) <- c ("x", "y")
index <- geodist_min (x, y, measure = "Haversine")
# 'index' is a vector of 50 values indexing elements of `y` corresponding to
# minimal distances to each element of `x`. It is exactly the same as the
# value returned by these lines:
d0 <- geodist (x, y, measure = "Haversine")
index0 <- apply (d0, 1, which.min)
identical (index, index0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.