I am trying to run the osmar navigation demo, in R. This demo will use osmar and igraph plot a traffic route around Munich city centre, based on openstreetmap data.
I am using R version 3.1.1 on Lubuntu
The demo, and the osmar library are detailed here http://journal.r-project.org/archive/2013-1/eugster-schlesinger.pdf
To run the demo I type,
library("osmar")
library("igraph") # The demo tries to call igraph0, but this is
# no-longer available in my version of R, so I
# have changed it to "igraph"
demo("navigator")
The demo runs perfectly until it reaches the igraph section.
gr_muc<-as_igraph(hways_muc) # make a graph of the highways from openstreetmap
summary(gr_muc)
This should return
Vertices: 2381
Edges: 2888
Directed: TRUE
No graph attributes.
Vertex attributes: name.
Edge attributes: weight, name.
But for me it returns
IGRAPH DNW-2385 2894 --
attr: name (v/c), weight (e/n), name (e/n)
I know that gr_muc
is a graph because the commands E(gr_muc)
and V(gr_muc)
return lists of edges and vertices.
Then the demo runs
route <- get.shortest.paths(gr_muc,from = as.character(hway_start_node),to = as.character(hway_end_node))[[1]]
and returns the error
At structural_properties.c:4482 :Couldn't reach some vertices
Which means that it couldn't link the start and end vertices. Then the script fails.
What do I change to make the demo script run, and why is it not working?
There are some one-way streets that prevent the start and end node being connected. Here's some scrappy code that plots the nodes reachable from the
hway_start
node:Note that you can't get to the top right which is where the end node is in the demo.
You can work round this if you don't mind driving the wrong way up one-way streets by making the graph undirected:
and now you have a route:
BUT the return from
get_shortest_paths
is a list of lists, so you need to get the first component ofroute
to continue the demo code:and then plot:
So I think firstly, the start and end node are not connected along directed ways, and secondly there's a bug in the demo code so that doesn't get the correct element of the return from
get_shortest_paths
. Its nothing to do withigraph0
.