help needed regarding package OSRM

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

help needed regarding package OSRM

Timothée Giraud-2

osrmRoute() requests a route between 2 points, it can return a
SpatialLinesDataFrame of the route with travel time (minutes) and travel
distance (kilometers) in its data slot.

osrmTable() requests a travel time matrix between a set of points, it
can return a matrix in minutes between sources and destinations.

The OSRM server cannot return a travel distance matrix (in km).

Thus, the only solution I see for now is to use a loop (or apply or
whatever) with osrmRoute() :


mat <- data.frame(i = character(), j = character (),
                   time = numeric(), distance = numeric(),
                   stringsAsFactors = F)
k = 1
for (i in 1:2){
   for (j in 6:8){
     rout <- osrmRoute(src = com[i, c("comm_id", "lon","lat")],
                       dst = com[j, c("comm_id", "lon","lat")], sp = T)
     mat[k, ] <- as.vector(rout@data[1,])
     k <- k + 1

Note that I use the github version of the package. This version is
adapted to last changes made on the demo server.

Note also that I use a Sys.sleep(0.5)instruction in the loop to be
gentle with the public OSRM demo server.

If you use your own OSRM server, the CRAN version will work and the
Sys.sleep() instruction is useless.

Timothée Giraud

R-sig-Geo mailing list
[hidden email]