Simplify road network by adding nodes at turns in edges and drawing straight line between the nodes #222
-
Hi all, I am using road network data from OSM in an ABM made in NetLogo. I am having trouble with agents getting stuck in the network and would therefore like to simplify the network. I would like to simplify it by adding nodes at turns in edges and drawing straight line between the nodes. This will make my turn less smooth, but this is manageable. Below some code to illustrate and a image of what I mean to do. I have spoken to Luuk and understand this is not yet possible in sfnetwork, however, I was hoping someone here might know a solution to my problem... Thanks in advance! # get Amsterdam centre boxed in
area <- getbb("Amsterdam")
#load streets from OSM
streets <- area %>%
opq() %>%
add_osm_feature(key = "highway", value = c("motorway",
"trunk", "primary", "secondary",
"tertiary", "unclassified", "residential",
"motorway_link", "trunk_link", "primary_link",
"secondary_link", "tertiary_link", "living_street", "road", "unclassified",
"pedestrian")
) %>%
osmdata_sf(quiet = FALSE)
streets_4326 <- streets$osm_lines
# make osm file into sfnetwork file
my_sfn <- as_sfnetwork(streets_4326, directed = TRUE, length_as_weight = TRUE)
tm_shape(smoothed %>% activate(edges) %>% as_tibble() %>% st_as_sf()) +
tm_lines() +
tm_shape(smoothed %>% activate(nodes) %>% as_tibble() %>% st_as_sf()) +
tm_dots() +
tmap_options(basemaps = 'OpenStreetMap')
should be this: (I know I still have to use to_spatial_subdivision here first to make a node at "Gedempte Hamerkanaal") |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi! I think that what you are proposing might be doable after implementing #177. In particular, I think you could adopt the following approach:
The main problem here is that we are assuming that there exists an OSM node at each turn but, looking at the figures online, I think this is a reasonable assumption. What do you think? |
Beta Was this translation helpful? Give feedback.
-
I ended up the using the Ramer-Douglas-Peucker algorithm to do this! |
Beta Was this translation helpful? Give feedback.
I ended up the using the Ramer-Douglas-Peucker algorithm to do this!