Fast search for the nearest lines to a set of points
nn_line(point, lines, k = 50, ncores = 1)
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 |
Returns an list of ids and distances
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
.
Other OSM:
cluster_junction()
,
line_segment_sf()
,
nn_point()
,
osm_consolidate()
,
osm_get_junctions()
,
osm_main_roads()
if (FALSE) { crash_road_nn = nn_line(crash_road, osm, ncores = 5) }