【发布时间】:2021-07-05 07:27:06
【问题描述】:
我在以下环境下运行以下代码:
R:4.1.0
包: 科幻:1.0.0 dplyr:1.0.7
看完之后 https://gis.stackexchange.com/questions/280671/r-create-multipolygon-from-overlapping-polygons-using-sf-package ,我在尝试玩 sf 包时遇到了一些问题。
我遇到的问题是以下代码:
library(sf)
library(dplyr)
poly <- data.frame(
lon = c(0, 1, 1, 0, 0.5),
lat = c(0, 0, 1, 1, 0.5),
var = c(1, 1, 1, 1, 1)
) %>%
st_as_sf(coords = c("lon", "lat"), dim = "XY") %>% st_set_crs(4326) %>%
group_by(var) %>%
summarise() %>% st_cast("POLYGON")
plot(poly)
代码的输出图是the following
,我认为它会按照原始数据框的顺序来创建多边形。即 (0,0) -> (1,0) -> (1,1) -> (0,1) -> (0.5,0.5) -> (0,0),应该看起来像 this picture。
我想知道是否有办法指定点连接的顺序?我在这个例子中使用了 set_convex_hull() 但输出只是一个正方形,这是有道理的,因为凸包的定义。我浏览了 sf 文档网站https://r-spatial.github.io/sf/articles/sf1.html,但仍然找不到解决方案。在研究这个包的使用时,我觉得我一定错过了一些关键词或方向。如果有人有任何建议,将不胜感激。
【问题讨论】: