Extract the indices of nearest nodes or edges to given spatial features
Source:R/nearest.R
nearest_ids.Rd
Extract the indices of nearest nodes or edges to given spatial features
Value
An integer vector with each element containing the index of the
nearest node or edge to the corresponding spatial features in y
.
Details
To determine the nearest node or edge to each feature in y
the function st_nearest_feature
is used. When extracting
nearest edges, spatially explicit edges are required, i.e. the edges table
should have a geometry column.
Examples
library(sf, quietly = TRUE)
net = as_sfnetwork(roxel)
pts = st_sample(st_bbox(roxel), 6)
nearest_node_ids(net, pts)
#> [1] 761 256 8 353 985 730
nearest_edge_ids(net, pts)
#> [1] 618 144 4 210 1192 939