Interface Between R and the OpenStreetMap-Based Routing Service OSRM

An interface between R and the OSRM API. OSRM is a routing service based on OpenStreetMap data. See < http://project-osrm.org/> for more information. This package allows to compute distances (travel time and kilometric distance) between points and travel time matrices.


Version Travis-CI Build Status

Interface Between R and the OpenStreetMap-Based Routing Service OSRM

Description

OSRM is a routing service based on OpenStreetMap data. See http://project-osrm.org/ for more information. This package allows to compute distances (travel time and kilometric distance) between points and travel time matrices.

This package relies on the usage of a running OSRM service (tested with v5.22.0 of OSRM).

You can run your own instance of OSRM following guidelines provided here: https://github.com/Project-OSRM/osrm-backend.
The simplest solution is probably the one based on docker containers.

To set the OSRM server, use the osrm.server option: options(osrm.server = "http://address.of.the.server/").
To set the profile ("driving" is set by default and it is the only profile available on the demo server), use the osrm.profile option: options(osrm.profile = "name.of.the.profile").
A typical setup, corresponding to the Docker example, would be:
options(osrm.server = "http://0.0.0.0:5000/", osrm.profile = "driving")

⚠️ You must be careful using the OSRM demo server:

Features

  • osrmTable Get travel time matrices between points.

  • osrmRoute Get the shortest path between two points.

  • osrmTrip Get the travel geometry between multiple unordered points.

  • osrmIsochrone Get polygons of isochrones.

Demo

osrmTable

library(osrm)
data("berlin")
# Travel time matrix
distA <- osrmTable(loc = apotheke.sf[1:5,])
distA$durations
440338666 538057637 977657079 3770254015 364363337
440338666 0.0 24.2 48.0 26.9 15.0
538057637 27.1 0.0 44.2 16.4 22.6
977657079 47.6 41.7 0.0 35.0 36.2
3770254015 28.7 16.9 34.6 0.0 17.0
364363337 15.4 20.7 34.4 15.9 0.0

osrmRoute

library(osrm)
library(sf)
library(cartography)
data("berlin")
route <- osrmRoute(src = apotheke.sf[74,], dst = apotheke.sf[55,],
                   overview = "full", returnclass = "sf")
# Display the path
osm <- getTiles(x = route, crop = TRUE, type = "osm", zoom = 13)
tilesLayer(osm)
plot(st_geometry(route), lwd = 4, add = TRUE)
plot(st_geometry(route), lwd = 1, col = "white", add = TRUE)
plot(st_geometry(apotheke.sf[c(74,55),]), pch = 20, col = "red", add = TRUE)

osrmTrip

library(osrm)
library(sf)
library(cartography)
data("berlin")
# Get a trip with a SpatialPointsDataFrame
trips <- osrmTrip(loc = apotheke.sf[10:20,], returnclass="sf")
trip <- trips[[1]]$trip
osm2 <- getTiles(x = trip, crop = TRUE, type = "cartolight", zoom = 11)
tilesLayer(x = osm2)
plot(st_geometry(trip), col = "black", lwd = 4, add = TRUE )
plot(st_geometry(trip), col = c("red", "white"), lwd = 1, add=TRUE)
plot(st_geometry(apotheke.sf[10:20,]), pch = 21, bg = "red", cex = 1.5, add=TRUE)

osrmIsochrone

library(osrm)
library(sf)
library(cartography)
data("berlin")
iso <- osrmIsochrone(loc = apotheke.sf[87,], returnclass="sf",
                     breaks = seq(from = 0, to = 14, by = 2), res = 50)
osm3 <- getTiles(x = iso, crop = FALSE, type = "osm", zoom = 12)
tilesLayer(x = osm3)
bks <- sort(c(unique(iso$min), max(iso$max)))
cols <- paste0(carto.pal("turquoise.pal", n1 = length(bks)-1), 80)
choroLayer(x = iso, var = "center", breaks = bks,
           border = NA, col = cols,
           legend.pos = "topleft",legend.frame = TRUE,
           legend.title.txt = "Isochrones\n(min)",
           add = TRUE)
plot(st_geometry(apotheke.sf[87,]), pch = 21, bg = "red", 
     cex = 1.5, add=TRUE)
 

Installation

  • Development version on GitHub
remotes::install_github("rCarto/osrm")
  • Stable version on CRAN
install.packages("osrm")

Community Guidelines

One can contribute to the package through pull requests and report issues or ask questions here.

News

osrm version 3.3.0 (Release date: 2019-04-29)

This version should not break previous code.

Major changes

  • sf support in all functions for input (src, dst, loc) and output (returnclass="sf")
  • The algorithm for isochrone has been changed to a more robust one that use isoband package, results may differ...
  • add apotheke.sf sf POINT in the package dataset "berlin".
  • examples have been simplified and mainly cover sf use.

osrm version 3.2.0 (Release date: 2018-12-12)

Minor changes

  • Add the exclude option to exclude some road types. Thanks to PR #32 by @mbask
  • Better info message when the public server receive too many requests.
  • Add a "measure" arg to osrmTable to obtain distance table (meters). fix #33.
  • Berlin example in README

osrm version 3.1.1 (Release date: 2018-03-12)

Minor changes

  • Put sp in Import rather than in Depends
  • bug fix in osrmTrip.
  • Better error messages.

osrm version 3.1.0 (Release date: 2017-06-08)

Minor changes

  • Use last version of cartography in examples
  • Adaptation to the current osrm demo server (ex. gepaf arg in osrmTable).
  • Examples in Berlin instead of north of France, easier with OSRM example docker image

osrm version 3.0.2 (Release date: 2017-06-08)

Minor changes

  • set the grid size for computing isochrones in osrmIsochrone (more precise isopleth maps)
  • fix osrmTrip

osrm version 3.0.1 (Release date: 2017-03-31)

Minor changes

  • Enable changing the profile via options(osrm.profile = "name.of.the.profile")(driving is set by default).
  • Small fixes and adaptations to the API (in osrmTrip mainly)

osrm version 3.0.0 (Release date: 2016-05-10)

This is a major release. Changes have been made to reflect the evolution of the OSRM routing service/engine. The backward compatibility is not ensured. The osrm package works with the version 5.0.0 of the OSRM API.

Major changes:

  • osrmViaroute is suppressed, use osrmRoute with overview = FALSE instead.
  • osrmViarouteGeom is replaced by osrmRoute. osrmRoute offers simplified or detailed (full) route geometry via overview parameter.
  • Functions now accept sp objects and data.frames.
  • Add osrmIsochrone. This function computes a SpatialPolygonsDataFrame of isochrones.
  • Add osrmTrip. This function gets the travel geometry between multiple unordered points.
  • Under the hood: some function now use google encoded polylines via gepaf package.

osrm version 2.0.0 (Release date: 2016-01-20)

This is a major release. Changes have been made to reflect the evolution of the OSRM routing service/engine. The backward compatibility is not ensured. The osrm package works with the version 4.9.0 of the OSRM API.

Major changes:

  • Supression of osrmTableOD and osrmTableErrors
  • Different parameters names and output in each functions
  • XML and reshape2 packages are no longer imported

osrm version 1.1 (Release date: 2015-11-06)

Changes:

  • Install instruction in README
  • Add a SpatialLinesDataFrame export to the osrmViaRouteGeom
  • Add the \dontrun{} instruction to all examples due to potential public API downtime and to prevent excessive use of the public API via regular checks.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("osrm")

3.3.2 by Timothée Giraud, 2 months ago


https://github.com/rCarto/osrm


Report a bug at https://github.com/rCarto/osrm/issues


Browse source code at https://github.com/cran/osrm


Authors: Timothée Giraud [cre, aut] , Robin Cura [ctb] , Matthieu Viry [ctb]


Documentation:   PDF Manual  


Task views: Web Technologies and Services


GPL-3 license


Imports jsonlite, RCurl, utils, stats, lwgeom, isoband, methods, gepaf, sp, sf

Suggests cartography


Imported by MCI2.

Suggested by stplanr.


See at CRAN