nearest_ids: Extract the indices of nearest nodes or edges to given...

nearest_idsR Documentation

Extract the indices of nearest nodes or edges to given spatial features

Description

Extract the indices of nearest nodes or edges to given spatial features

Usage

nearest_node_ids(x, y, focused = TRUE)

nearest_edge_ids(x, y, focused = TRUE)

Arguments

x

An object of class sfnetwork.

y

Spatial features as object of class sf or sfc.

focused

Should only the indices of features that are in focus be extracted? Defaults to TRUE. See focus for more information on focused networks.

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.

Value

An integer vector with each element containing the index of the nearest node or edge to the corresponding spatial features in y.

Examples

library(sf, quietly = TRUE)

net = as_sfnetwork(roxel)
pts = st_sample(st_bbox(roxel), 6)

nearest_node_ids(net, pts)
nearest_edge_ids(net, pts)


luukvdmeer/sfnetworks documentation built on Nov. 21, 2024, 4:54 a.m.