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
Hi,

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() :

devtools::install_github("rCarto/osrm")

library(osrm)
data("com")
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
     Sys.sleep(0.5)
   }
}
mat

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]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo