Great news for all enthusiasts of R stats – the popular open source stats system: the HeiGIT ORS team has developed a package to facilitate querying the openrouteservice API from R. It allows you to painlessly consume the following services:
- directions (routing)
- geocode
- isochrones (accessibilty)
- time-distace matrix
- pois (points of interest)
You do not have to fiddle with processing any street network data, but will use the most recent OpenStreetMap data from ORS directly – worldwide!
The latest version can be installed directly from GitHub with devtools::install_github("GIScience/openrouteservice-r")
.
It’s really easy to get started. For example, finding a route from Heidelberg to Kraków takes just a few lines of code.
And with the help of leaflet it’s even possible to visualize the results directly in R. Neat! Test the example:
library("openrouteservice") # one-time API key set-up # ors_api_key("<your-api-key>") # query for coordinates locations <- lapply(c("Heidelberg", "Kraków"), ors_geocode) coordinates <- lapply(locations, function(x) x$features[[1]]$geometry$coordinates) # find route route <- ors_directions(coordinates, format="geojson") # route length in kilometres and duration in hours unlist(route$features[[1]]$properties$summary) / c(1000, 3600) ## distance duration ## 1051.861300 9.205167 # draw on map using leaflet library(leaflet) leaflet() %>% addTiles() %>% addGeoJSON(route, fill=FALSE) %>% fitBBox(route$bbox)
For more examples and an overview of the offered functionality see package vignette. Enjoy!
And yes, of course there is also an ORS Python package available! JS under progress… Stay tuned!