You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! A few days ago I was chatting with a friend of mine (@GithubSom) and he asked me if it's possible to preserve node attributes at points with identical coordinates using st_network_blend().
For example, the following code defines a nodes table with two points having identical coordinates but different attributes. The problem is that both points are collapsed into a unique point since they have the same spatial coordinates (and this is also documented in ?st_network_blend):
# packages
library(sf)
library(tidygraph)
library(sfnetworks)
# toy netmy_edges<- st_sfc(st_linestring(rbind(c(0, 0), c(1, 1))))
my_sfn<- as_sfnetwork(my_edges)
# two points with same coords (not exactly on the network) and different# attributesmy_points<- st_sf(
x= c("A", "B"),
geometry= st_sfc(
st_point(c(0.4, 0.6)), st_point(c(0.4, 0.6))
)
)
# blend the points into the network
st_network_blend(my_sfn, my_points)
#> # A sfnetwork with 3 nodes and 2 edges#> ##> # CRS: NA #> ##> # A rooted tree with spatially explicit edges#> ##> # Node Data: 3 x 1 (active)#> # Geometry type: POINT#> # Dimension: XY#> # Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1#> x#> <POINT>#> 1 (0 0)#> 2 (1 1)#> 3 (0.5 0.5)#> ##> # Edge Data: 2 x 3#> # Geometry type: LINESTRING#> # Dimension: XY#> # Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1#> from to x#> <int> <int> <LINESTRING>#> 1 1 3 (0 0, 0.5 0.5)#> 2 3 2 (0.5 0.5, 1 1)
Do you think it might be possible to adjust the function to take extra attributes into account? The main problem (and, IMO, it's quite difficult to solve it in general) is how to adjust the indices in the nodes and edges table (i.e. the from and to fields). In fact, we must take into account that new points lying at exactly the same coordinates must remain distinct and we may have to duplicate all relevant edges. For example, in the previous case, we might define a sfnetwork with the following nodes and edges table:
Clearly, the duplicated edges might raise even more problems for other functions. Moreover, I think that the way adopted to solve the "duplicated points at the same coordinate" problem is not unique.
Use case: road safety analysis where car crashes occurring at different time stamps might be located at exactly the same point (i.e. a roundabout or a traffic light).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi! A few days ago I was chatting with a friend of mine (@GithubSom) and he asked me if it's possible to preserve node attributes at points with identical coordinates using
st_network_blend()
.For example, the following code defines a nodes table with two points having identical coordinates but different attributes. The problem is that both points are collapsed into a unique point since they have the same spatial coordinates (and this is also documented in
?st_network_blend
):Created on 2022-09-01 with reprex v2.0.2
Do you think it might be possible to adjust the function to take extra attributes into account? The main problem (and, IMO, it's quite difficult to solve it in general) is how to adjust the indices in the nodes and edges table (i.e. the from and to fields). In fact, we must take into account that new points lying at exactly the same coordinates must remain distinct and we may have to duplicate all relevant edges. For example, in the previous case, we might define a sfnetwork with the following nodes and edges table:
Clearly, the duplicated edges might raise even more problems for other functions. Moreover, I think that the way adopted to solve the "duplicated points at the same coordinate" problem is not unique.
Use case: road safety analysis where car crashes occurring at different time stamps might be located at exactly the same point (i.e. a roundabout or a traffic light).
Beta Was this translation helpful? Give feedback.
All reactions