我有一个包含88个多边形的列表,其中每个只是一个包含经度列和长列的数据框,有没有一种简便的方法可以在传单中绘制此多边形? 例如,mi数据采用变量示例的格式,如下所示
df1 <- data.frame(lon=c(-71.53700 -71.51676 -71.51682 -71.51524 -71.53921 -71.53700), lat=c(-32.94082, -32.93327, -32.93325, -32.92814, -32.93408, -32.94082))
df2 <- data.frame(lon=c(-72.11527, -72.09601, -72.08983, -72.10905, -72.11527), lat=c(-36.61267, -36.61720, -36.60192, -36.59682, -36.61267))
example <- list(df1, df2)
答案 0 :(得分:0)
这是一个通过sf
将点转换为多边形的示例。请注意,您的第一个多边形基本上是一条线,因此我只绘制了第二个多边形。
library(tidyverse)
library(sf)
library(leaflet)
df1 <- data.frame(lon=c(-71.53700 -71.51676 -71.51682 -71.51524 -71.53921 -71.53700), lat=c(-32.94082, -32.93327, -32.93325, -32.92814, -32.93408, -32.94082))
df2 <- data.frame(lon=c(-72.11527, -72.09601, -72.08983, -72.10905, -72.11527), lat=c(-36.61267, -36.61720, -36.60192, -36.59682, -36.61267))
example <- list(df1, df2)
polys <- example %>%
bind_rows(.id = "df_id") %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326) %>%
group_by(df_id) %>%
summarise(geometry = st_combine(geometry)) %>%
st_cast("POLYGON")
leaflet(polys[2, ]) %>%
addPolygons()