{"word_count": 301, "character_count": 2177}
The osrm package is an interface between R and the OSRM API. OSRM is a routing service based on OpenStreetMap data.This package allows computing shortest paths and travel time matrices between points.A brief overview of osrm package functions:osrmTable Get travel time matrices between points.osrmViaroute Get travel time and travel distance between two points.osrmViarouteGeom Get the travel geometry between two points.This package relies on the use of a running OSRM service (tested with version 4.9.0 of the OSRM API).By default this service is the OSRM public API (API usage policy). It is possible to use a different server if you want to make intensive use of the API.Here is a short example of osrm usage (download data here):library(osrm) # to get paths between pointslibrary(cartography) # to plot a base maplibrary(rgdal) # to import/export shapefile# import a shapefileletter &#60;- readOGR(dsn="/home/tg/Bureau/", layer = "R")# get OpenStreetMap tiles on the regionmytiles &#60;- getTiles(spdf = letter, type = "osm")# # export the plot# # get size of the figure# sizes &#60;- getFigDim(spdf = letter, width = 474, mar = c(0,0,0,0))# png("/home/tg/Bureau/R.png", width = sizes[1], height = sizes[2])par(mar=c(0,0,0,0))plot(letter, col = NA)tilesLayer(mytiles, add=T)# plot the pointsplot(letter, add=T, pch = 20, col = 'blue', cex = 2)# Create a SpaTialLinesDataFrame of all the roadsdf &#60;- data.frame(coordinates(letter))names(df) &#60;- c("X", "Y")df$id &#60;- 1:nrow(df)for (i in 1:(nrow(df)-1)){  road &#60;- osrmViarouteGeom(src = df[i,3:1],                            dst = df[i+1,3:1],                            sp =TRUE)  if (exists("myroads")){    myroads &#60;- rbind(myroads, road)  }else{    myroads &#60;- road  }}# and plot itplot(myroads, col = "red", lwd = 2, add=TRUE)mtext("Data: OpenStreetMap &#38; contributors, ODBl; routes: OSRM",       side = 1, line =  -1, adj = 0, cex = 0.8, font = 2)# dev.off()# # export the road layer# writeOGR(obj = myroads, dsn="/home/tg/Bureau",#          layer = "myroads", driver = "ESRI Shapefile")The next version of the package (now on GitHub) will allow SpatialPointsDataFrames as inputs of the functions.