Fast search for the nearest point to another set of points

nn_point(x, y, clusters = NULL)

Arguments

x

a SF data frame of POINTS

y

a SF data frame of POINTS

clusters

a list of integers, default NULL

Value

Returns an list of ids and distances

Details

If clusters is null will find the nearest y point for each x point and return a list of two vectors indexes of y length(x) and a distances length(x). If clusters is a list e.g. from cluster_junction then the indexes are replaced with the matching indexes of clusters

See also

Examples

if (FALSE) {
junctions = osm_get_junctions(osm)
junction_clusters = cluster_junction(junctions)

# Find the nearest junction
near_junction = nn_point(crash_junction, junctions)

# Find the nearest junction cluster
near_cluster = nn_point(crash_junction, junctions, clusters = junction_clusters$junction_ids)
}