Describe the bug
in st_network_cost() one gives to arguments either as node indices or sf POINTS. However igraph::distances() does not allow duplicated to nodes. This is fine when adding node indices manually, but when passing sf POINTS, this is harder to control and find.
Internally we use set_path_endpoints to find the nearest to node indices inside the network. However, the same function is also used in st_network_paths() where this is not an issue.
Reproducible example
library(sf)
library(sfnetworks)
net = as_sfnetwork(roxel, directed = FALSE) %>%
st_transform(3035)
st_network_cost(net, 1, c(3, 2, 3))
#> Error in (function (graph, v = V(graph), to = V(graph), mode = c("all", : At structural_properties.c:507 : Duplicate vertices in `to', this is not allowed, Invalid value
p1 = st_geometry(net, "nodes")[1]
p2 = st_geometry(net, "nodes")[9]
p3 = st_sfc(p1[[1]] + st_point(c(500, 500)), crs = st_crs(p1))
p4 = st_sfc(p1[[1]] + st_point(c(500.2, 500.2)), crs = st_crs(p1))
p5 = st_sfc(p2[[1]] + st_point(c(-500, -500)), crs = st_crs(p2))
pts1 = c(p1, p5)
pts2 = c(p2, p3, p4)
st_network_cost(net, pts1, pts2)
#> Error in (function (graph, v = V(graph), to = V(graph), mode = c("all", : At structural_properties.c:507 : Duplicate vertices in `to', this is not allowed, Invalid value
Expected behaviorst_network_cost() only passes unique values to the to argument, with a warning.
Describe the bug in
st_network_cost()
one givesto
arguments either as node indices orsf POINTS
. Howeverigraph::distances()
does not allow duplicatedto
nodes. This is fine when adding node indices manually, but when passingsf POINTS
, this is harder to control and find.Internally we use
set_path_endpoints
to find the nearestto
node indices inside the network. However, the same function is also used inst_network_paths()
where this is not an issue.Reproducible example
Expected behavior
st_network_cost()
only passesunique
values to theto
argument, with a warning.