New version of osrm

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, travel time and travel distance matrices between points.

The osrm package functions are:

  • osrmTable(): travel time and travel distance matrices between points.
  • osrmRoute(): shortest path between two points.
  • osrmTrip(): shortest trip between multiple unordered points.
  • osrmIsochrone(): polygons of isochrones

This package relies on the use of an OSRM server (tested with version 5.22.0 of OSRM).
By default the package uses the OSRM demo server (API usage policy). It is possible to use a different server if you want to make intensive use of the API. You can run your own instance of OSRM following guidelines provided on the OSRM GitHub repository. The simplest solution is the one based on docker containers.

The main change introduced by this update is the support of sf objects as input and output in all functions: using the argument returnclass = "sf" in osrmRoute(), osrmIsochrone() and osrmTrip() allows to output sf objects.

The algorithm for isochrones has been changed to a more robust one that uses isoband package.

In the following example more than 800 shortest paths to the useR2019 conference in Toulouse are displayed:

In the next example isochrones around Toulouse are displayed:

Code for the figures is in this gist.

The popcircle package

The popcircle package has been released on GitHub. This one-function package computes circles with areas scaled to a variable and displays them using a compact layout (higher values in the center, lower values at the periphery). Original polygons are scaled to fit inside these circles (size are roughly proportional, not strictly).

The circles creation relies on packcircles, spatial data manipulation relies on sf.

## Package install:

This is a typical example of the package usage based on the dataset shipped with the package. We use cartography to display labels.

mtq <- st_read(system.file("gpkg/mtq.gpkg", 
res <- popcircle(x = mtq, var = "POP")
circles <- res$circles
shapes <- res$shapes
par(mar = c(0,0,0,0))
plot(st_geometry(circles), col = "#bcd39c", 
     border = "white", bg = "#eafdcf")
plot(st_geometry(shapes), col = "#fffc99", 
     border = "#fffc99", add = TRUE)
labelLayer(x = circles[1:20,], txt = "LIBGEO",
           halo = TRUE, col ="#8e8358", 
           cex = seq(.8,.4, length.out = 20),
           font = 2, bg = "white", r = .15, 
           overlap = FALSE)

The next example was a bit more difficult to design. We had to work on some multipolygons countries (e.g. France, USA or Russia) in order to keep only the largest polygon.

Code for the figure
Code for the figure

As popcircle produces sf objects it is possible to display them interactively:

You can find here an example of interactive visualisation using leaflet.

popcircle changes the position of spatial units. It will work better with regions already well known to the target audience. Chances are that the first figure on Martinique municipalities will be more appropriate and effective for the inhabitants of Martinique.