一种方法是使用sf
来自这个优秀答案的包here https://stackoverflow.com/a/44339406/4083743。在您的数据上实施leaflet
:
library(sf)
library(leaflet)
lst <- lapply(1:nrow(df), function(x){
res <- matrix(c(df[x, 'maxlat'], df[x, 'maxlon'],
df[x, 'maxlat'], df[x, 'minlon'],
df[x, 'minlat'], df[x, 'minlon'],
df[x, 'minlat'], df[x, 'maxlon'],
df[x, 'maxlat'], df[x, 'maxlon'])
, ncol =2, byrow = T
)
st_polygon(list(res))
})
df$geomtry <- st_sfc(lst)
str(df)
sfdf <- st_sf(df)
leaflet() %>%
addTiles() %>%
addPolygons(data = sfdf)