小编tre*_*evi的帖子

如何在执行st_union()操作后将多面几何体分成几个多边形对象?

我有一组多边形,其中一些多边形相交和/或触摸(公共边框).我正在使用R的sf包对多边形执行操作.到目前为止,我的方法是使用sf::st_union()连接相邻和交叉多边形的方法,但它也将所有多边形组合成 MULTIPOLYGON几何.我想将每个多边形分隔为一个sf(data.frame)类,其中每个多边形对象在一个行中显示为一行data.frame

我在下面举例说明.我首先创建一个示例数据集:

    # Creating four example polygons, of which two (two squares) are neighbors:

    p1 <- rbind(c(0,0), c(1,0), c(3,2), c(2,4), c(1,4), c(0,0))
    pol1 <-st_polygon(list(p1))
    p2 <- rbind(c(3,0), c(4,0), c(4,1), c(3,1), c(3,0))
    pol2 <-st_polygon(list(p2))
    p3 <- rbind(c(4,0), c(4,1), c(5,1), c(5,0),c(4,0))
    pol3 <-st_polygon(list(p3))
    p4 <- rbind(c(3,3), c(4,2), c(4,3), c(3,3))
    pol4 <-st_polygon(list(p4))

    d = data.frame(some_attribute = 1:4)
    d$geometry = st_sfc(pol1,pol2,pol3,pol4)
    df = st_as_sf(d)

    class(df)
    #[1] "sf"         "data.frame"

    df
    # Simple feature collection with 4 features and …
Run Code Online (Sandbox Code Playgroud)

join r spatial

6
推荐指数
1
解决办法
2938
查看次数

标签 统计

join ×1

r ×1

spatial ×1