r - Mapping a circle radius of a city in Leaflet in R
问题描述
I have a list of cities in R that I want to map a 75 mile radius around in leaflet in r.
I know addCircle
will map a circle around the given latitude and longitude, but i dont know how to get the lat and long for the cities.
解决方案
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)
推荐阅读
- php - 如何使用 laravel 从两个集合创建一个集合
- javascript - node.js 护照反序列化用户没有被调用
- flutter - CupertinoDatePicker A RenderFlex 在底部被 Infinity 像素溢出
- c - 为 C 和 Fortran 程序提供相同的输入但在 Householder reduction (tred2) 中得到不同的输出?
- java - 我正在我的 java 类中处理数据库,我需要帮助弄清楚如何更新数据库中的特定值/列
- javascript - String.replaceAll 在 JS 的两个参数中使用正则表达式
- php - 从 HTML/PHP Web 表单中直接提取信息到 .xlsm 格式的现有 Excel 文件中
- node.js - NodeJS Axios 请求返回一个奇怪的字符串
- ubuntu - 每 5 小时更新一次 crontab 以 tar 新的/更新的文件
- html - 如何将侧边栏和正文部分固定在同一行?