match_nrst_haversine {hutilscpp} | R Documentation |
Match coordinates to nearest coordinates
Description
When geocoding coordinates to known addresses, an efficient way to
match the given coordinates with the known is necessary. This function provides this
efficiency by using C++
and allowing approximate matching.
Usage
match_nrst_haversine(
lat,
lon,
addresses_lat,
addresses_lon,
Index = seq_along(addresses_lat),
cartesian_R = NULL,
close_enough = 10,
excl_self = FALSE,
as.data.table = TRUE,
.verify_box = TRUE
)
Arguments
lat , lon |
Coordinates to be geocoded. Numeric vectors of equal length. |
addresses_lat , addresses_lon |
Coordinates of known locations. Numeric vectors of equal length
(likely to be a different length than the length of |
Index |
A vector the same length as |
cartesian_R |
The maximum radius of any address from the points to be geocoded. Used to accelerate the detection of minimum distances. Note, as the argument name suggests, the distance is in cartesian coordinates, so a small number is likely. |
close_enough |
The distance, in metres, below which a match will be considered to have occurred. (The distance that is considered "close enough" to be a match.) For example, May be provided as a string to emphasize the units, e.g. |
excl_self |
(bool, default: |
as.data.table |
Return result as a |
.verify_box |
Check the initial guess against other points within the
box of radius |
Value
A list (or data.table
if as.data.table = TRUE
) with two elements,
both the same length as lat
, giving for point lat,lon
:
pos
the position (or corresponding value in
Table
) inaddresses_lat,addresses_lon
nearest tolat, lon
.dist
the distance, in kilometres, between the two points.
Examples
lat2 <- runif(5, -38, -37.8)
lon2 <- rep(145, 5)
lat1 <- c(-37.875, -37.91)
lon1 <- c(144.96, 144.978)
match_nrst_haversine(lat1, lon1, lat2, lon2)
match_nrst_haversine(lat1, lon1, lat1, lon1, 11:12, excl_self = TRUE)