i play around with https://rdrr.io/rforge/osmar/src/demo/navigator.R (Navigator Demo). I would like to find several paths insted of just one.
It seems i can not use the function all_simple_paths
since it will never terminate.
Would it be possible after i find a shortest path with
route <- get.all.shortest.paths(gr_muc, from = as.character(hway_start_node), to = as.character(hway_end_node))[[1]]
increase weight of the whole route and search again with the function get.all.shortest.paths
to find n ext alternative?
Is this the right approach or is there an alternative?
Thank you in advance!
library(tidyverse)
library(osmdata)
library(osmar) # (geosphere is inclued in osmar)
library(sf)
library(ggmap)
library(prettymapr)
library(leaflet)
library(igraph)
library(stplanr)
library(rgeos)
### Download and extract data: #######################################
download.file("http://osmar.r-forge.r-project.org/muenchen.osm.gz",
"muenchen.osm.gz")
system("gzip -d muenchen.osm.gz")
### Import subset based on bounding box: #############################
src <- osmsource_osmosis(file = "muenchen.osm",
osmosis = "osmosis")
muc_bbox <- center_bbox(11.575278, 48.137222, 60000, 60000)
muc <- get_osm(muc_bbox, src)
hways_muc<-muc
gr_muc <- as_igraph(hways_muc)
hway_start_node <- local({
id <- find(muc, node(tags(v == "Sendlinger Tor")))[1]
find_nearest_node(muc, id, way(tags(k == "highway")))
})
hway_start <- subset(muc, node(hway_start_node))
hway_end_node <- local({
id <- find(muc, node(attrs(lon > 11.59 & lat > 48.150)))[1]
find_nearest_node(muc, id, way(tags(k == "highway")))
})
hway_end <- subset(muc, node(hway_end_node))
route <- get.all.shortest.paths(gr_muc,
from = as.character(hway_start_node),
to = as.character(hway_end_node),
mode = "all")[[1]]