how to plot multiple isochrone on leaflet map in R

1.4k views Asked by At

i can plot one isochrone in R at a time using Rmapzen package with this code, each isochrone is generated as a sp object, is there any way to create multiple isochrone on the same map like the attached picenter image description here?

2

There are 2 answers

0
Louisa Bainbridge On

Hi it’s possible to create multiple isochrones on a leaflet map using the TravelTime API. You just need to set a departure/arrival time for each shape, transport mode and maximum travel time for the isochrone. Take a look at a sample request and get API keys from here

(Disclaimer: I work for the company responsible for creating this API)

0
Claudio Paladini On

This works for me. A bit messy though.. Remember to change the mapzen key

library(rmapzen)
library(leaflet)
library(ggmap)
#packages

Sys.setenv(MAPZEN_KEY = "mapzen-******")
#API key

ucb <- geocode("Via Giovanni Spadolini 7, Milan, Italy")
ucb1 <- geocode("Via Valtellina 15, Milan, Italy")
#origin address

iso5 <- as_sp(mz_isochrone(
  ucb,
  costing_model = mz_costing$auto(),
  contours = mz_contours(5),
  polygons = TRUE
))
iso15 <- as_sp(mz_isochrone(
  ucb,
  costing_model = mz_costing$auto(),
  contours = mz_contours(15),
  polygons = TRUE
))
iso1_5 <- as_sp(mz_isochrone(
  ucb1,
  costing_model = mz_costing$auto(),
  contours = mz_contours(5),
  polygons = TRUE
))
iso1_15 <- as_sp(mz_isochrone(
  ucb1,
  costing_model = mz_costing$auto(),
  contours = mz_contours(15),
  polygons = TRUE
))

m = leaflet() %>%
  addProviderTiles("CartoDB.DarkMatter") %>%
  addPolygons(data = iso15, color = "green", fillColor = "green", fillOpacity = .5)%>%
  addPolygons(data = iso5, color = "blue", fillColor = "blue", fillOpacity = .5)%>%
  addPolygons(data = iso1_15, color = "green", fillColor = "green", fillOpacity = .5)%>%
  addPolygons(data = iso1_5, color = "blue", fillColor = "blue", fillOpacity = .5)
m