简体   繁体   English

如何在R中的小册子地图上绘制多个等时线

[英]how to plot multiple isochrone on leaflet map in R

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 pic 我可以使用带有此代码的 Rmapzen包一次在R中绘制一个等时线,每个等时线都是作为sp对象生成的,有没有办法在同一个地图上创建多个等时线,如附加图片 在此输入图像描述 ?

Hi it's possible to create multiple isochrones on a leaflet map using the TravelTime API. 您好,可以使用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 查看示例请求并从此处获取API密钥

(Disclaimer: I work for the company responsible for creating this API) (免责声明:我为负责创建此API的公司工作)

This works for me. 这适合我。 A bit messy though.. Remember to change the mapzen key 虽然有点凌乱..记得改变mapzen键

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM