Site icon R-bloggers

Shiny App: Drive Time Isochrones

[This article was first published on R on Thomas Roh, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The Open Source Routing Machine project is an excellent resource for computing routing and travel time estimates for road networks. It is an open source library that has a demo server to run API requests to. I’ll only be using one of the services (isochrones which I’ll explain below) in this blog post. To access the API there is a wonderful R package osrm that simplifies the necessary code.

For various urban/transportation planning or market analysis, one will probably be interested in the possible areas that can be reached by road within a certain amount of time. A representation of that is called an isochrone. An isochrone is a spatial object typically a polygon or multipolygon that shows a geographic region that can reach a point within the specified travel time parameters. Programmatically in R, all we need to do is specific the latitude and longtitude of interest and the travel time.

library(osrm)
osrmIsochrone(c(-95.9345,41.2565), breaks = 10)

The osrm package has some options behind the scenes that are preset for you. The call above has set the server to the demo server (you can set up your own server for reliability) and it has set the mode of transportation to “driving”. To change the profile, you have to adjust the option “osrm.profile”. I’ve been able to use “driving”, “bike”, and “walk” so far. You can find more documentation here: OSRM Documentation and osrm Github.

I’ve created a shiny app to show an example of building a sharp interface for end users to easily specify the parameters and download the geojson or shapefile for other uses. The app is in showcase mode (code is at the bottom) so you can see what else is going on behind the scenes with the sf and leaflet package.

Link to application

To leave a comment for the author, please follow the link and comment on their blog: R on Thomas Roh.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.