Fast search for the nearest lines to a set of points

nn_line(point, lines, k = 50, ncores = 1)

Arguments

point

a SF data frame of POINTS with projected CRS

lines

a SF data frame of lines with projected CRS

k

integer how many lines to search

ncores

integer how many cores to use in parallel processing, default = 1

Value

Returns an list of ids and distances

Details

The nearest line to a point is a non-trivial calculation which in theory requires checking the distance to every possible line. This function takes a shortcut by measuring distances to the centroids of lines, and then cross checking only nearby lines. The number of lines checked is defined by k. This process cannot guarantee 100% accuracy by is many orders of magnitude faster. To increase accuracy increase k.

See also

Examples

if (FALSE) {
crash_road_nn = nn_line(crash_road, osm, ncores = 5)
}