【问题标题】:Mapping a circle radius of a city in Leaflet in R在R中的Leaflet中绘制一个城市的圆半径
【发布时间】:2021-09-21 22:31:29
【问题描述】:

我有一个 R 中的城市列表,我想在 r 中的传单中绘制半径 75 英里的地图。

我知道addCircle 将围绕给定的经纬度绘制一个圆圈,但我不知道如何获取城市的经纬度。

【问题讨论】:

    标签: r


    【解决方案1】:
    library(tmaptools)
    library(sf)
    library(leaflet)
    cities <- c("Sacramento", "Santa Clarita")
    cities_new <- geocode_OSM(cities)
    #           query      lat       lon  lat_min  lat_max   lon_min   lon_max
    # 1    Sacramento 38.58106 -121.4939 38.43757 38.68551 -121.5601 -121.3627
    # 2 Santa Clarita 34.39166 -118.5426 34.34145 34.49610 -118.6133 -118.3788
    
    cities.sf <- cities_new %>% st_as_sf(coords = c("lon", "lat"), crs = 4326)
    cities.buffer <- cities.sf %>% sf::st_buffer( dist = 120700)
    
    leaflet() %>% addTiles() %>%
      addCircleMarkers(data = cities.sf, color = "red") %>%
      addPolygons(data = cities.buffer)
    

    【讨论】:

    • 我运行了你提供的所有库,得到了错误Error in geocode_OSM(cities1) : could not find function "geocode_OSM"
    • 也许你还需要安装 tmap-package
    • 尝试安装 tmaptools 手册中建议的软件包。
    猜你喜欢
    • 2015-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-25
    • 1970-01-01
    • 2014-02-28
    • 1970-01-01
    • 2017-06-06
    相关资源
    最近更新 更多