Closed luukvdmeer closed 4 years ago
After finding out about sf's st_nearest_feature(x,y)
: the proposed st_nearest_node(x,y)
function would be equal to st_nearest_feature(x,y)
where y
is an object of class sfnetwork
. Although the documentation specifies that argument y
should be of class sf
, sfc
or sfg
, it already works for sfnetworks
objects, because the function takes the geometries of the input objects, and st_geometry
works on sfnetwork
objects as well.
net = as_sfnetwork(roxel)
st_nearest_feature(st_centroid(roxel), net)
Still I think st_nearest_node
would be semantically more intuitive in the case of working with networks. Also, this will skip the need to have the nodes activated when applying the function.
Similarly, st_nearest_edge
would work on the edges.
After thinking more about it, this does not really fit good into tidygraph
philosophy. Rather than creating separate, but similar functions for nodes and edges, you should use the activate
verb and apply the same function.
Is your feature request related to a problem? Please describe. Especially when calculating shortest paths, it should be possible to enter any point in space as
to
andfrom
. Then, a function should find the nearest node in thesfnetwork
object, for both thisto
andfrom
point, and calculate the shortest path in the network accordingly. Also, when you have additional data that you want to join with the network, but the coordinates are not exactly matching, this functionality would be useful.Describe the solution you'd like A function
st_nearest_node
that takes an sfnetwork object and an sf/sfg/sfc object. Then, it will find for each feature in the sf/sfg/sfc object the nearest node in the sfnetwork object, and replace the geometry of the feature with the geometry of its nearest node.