-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when blending points into network #252
Comments
Maybe because multiple points are associated with a single point on the network? |
I think this is an error that occurs when blending sf objects with attributes into the network and every external point is matched with an existing node. Simpler reprex: #packages
library(sf)
#> Linking to GEOS 3.11.2, GDAL 3.6.2, PROJ 9.2.0; sf_use_s2() is TRUE
library(sfnetworks)
# toy-data
l <- st_linestring(rbind(c(0, 0), c(1, 1)))
sfc <- as_sfnetwork(st_sfc(l))
external_point <- st_sfc(st_point(c(-1, -1)))
# plot
# plot(sfc, axes = TRUE, xlim = c(-1.5, 2), ylim = c(-1.5, 2), cex = 2, lwd = 2)
# plot(external_point, col = "red", add = TRUE, pch = 20, cex = 2)
# blend sfc object
sfc2 <- st_network_blend(sfc, external_point)
# the output is identical to original net
igraph::identical_graphs(sfc, sfc2)
#> [1] TRUE
# since the closest point to "external_point" is the boundary point of l.
# Nevertheless, if I add an attribute to "external_point"
external_sf <- st_sf(
data.frame(x = "A"),
geometry = external_point
)
st_network_blend(sfc, external_sf)
#> Error in `[[<-.data.frame`(`*tmp*`, i, value = 3:2): replacement has 2 rows, data has 0 Created on 2023-08-11 with reprex v2.0.2 I think the error is here Lines 456 to 458 in 23a4125
since Lines 444 to 445 in 23a4125
and |
Thank you very much @agila5 and @Robinlovelace! I removed all attributes for the external points, which can then be blended into the network! May I ask, is it possible to fix it? What I want to do after blending is to extract the network nodes that are generated by the points blended: library(sf)
library(sfnetworks)
# toy-data
l = st_linestring(rbind(c(0, 0), c(1, 1)))
sfc = as_sfnetwork(st_sfc(l))
external_sf = st_sf(
data.frame(x = "A"),
geometry = external_point
)
# blend external points into the network (if successful)
sfc2 = st_network_blend(sfc, external_sf)
# extract the nodes that are generated by blending points
sfc2 %>%
activate("nodes") %>%
st_as_sf() %>%
filter(!is.na(A)) -> sf_point_blended Thus, it would be great if the external points had some attributes. |
Describe the bug
Hi there. Thanks for this handy package!
I just got an minor error that couldn't blend certain points into the road network:
This is strange because the
st_network_blend()
method works perfectly fine for my other data points. Only the points shown above couldn't be blended. The test data can be accessed here.Reproducible example
Expected behavior
The
sf_point_test
can be blended intosfnetwork_road_test
.R Session Info
Thank you very much for your kind guidance!
The text was updated successfully, but these errors were encountered: