【问题标题】:Spatial polygon intersection - multiple resulting polygons空间多边形相交 - 多个生成的多边形
【发布时间】:2020-02-17 09:03:25
【问题描述】:

我正在使用 R 空间工具 rgeos::gIntersection 和/或 raster::intersect 处理多边形的交集。在我的情况下,由于用于进行相交的多边形之一(Lpoly)的形状,相交的结果是两个多边形。然而,从summary() 函数看来,它只是创建了一个特性?!如何访问相交过程产生的两个几何图形?此外,我想根据覆盖特定空间点(坐标对)的标准仅选择一个生成的多边形:

A <- c(0,0)
B <- c(0,3)
C <- c(2,3)
D <- c(2,1)
E <- c(3,1)
F <- c(3,3)
G <- c(5,3)
H <- c(5,0)
Lpoly <- SpatialPolygons(list(Polygons(list(Polygon(rbind(A,B,C,D,E,F,G,H))),1)))
plot(Lpoly)

A2 <- c(1,2)
B2 <- c(1,3)
C2 <- c(4,3)
D2 <- c(4,2)
intersect_poly <-  SpatialPolygons(list(Polygons(list(Polygon(rbind(A2,B2,C2,D2))),1)))
plot(intersect_poly,col="red",add=T) 

i <- intersect(Lpoly,intersect_poly)
i_rgeos <- rgeos::gIntersection(Lpoly,intersect_poly)
summary(i_rgeos)

plot(i_rgeos,add=T,col="green")

如何只选择一个多边形和/或为每个生成的多边形获取独特的特征?如何访问也覆盖坐标c(1.5,2.5) 的生成多边形?

解决方法#1: 我找到了一个基于:

i_rgeos <- disaggregate(i_rgeos)
i_rgeos <- i_rgeos[as.vector(which(over(i_rgeos,p)>0)),] #where p = spatial point of interest

【问题讨论】:

    标签: r polygon spatial intersection


    【解决方案1】:

    不确定rgeos 怎么做,但是使用sf 包,我们可以轻松地将 shapefile 转换为不同的类型,在这种情况下,从 MULTIPOLYGON 到 POLYGON,我们只需先将 i_rgeos 转换为简单的功能。

    library(sf)
    
    st_as_sf(i_rgeos) %>% st_cast("POLYGON")
    #> Simple feature collection with 2 features and 0 fields
    #> geometry type:  POLYGON
    #> dimension:      XY
    #> bbox:           xmin: 1 ymin: 2 xmax: 4 ymax: 3
    #> epsg (SRID):    NA
    #> proj4string:    NA
    #>                         geometry
    #> 1 POLYGON ((1 3, 2 3, 2 2, 1 ...
    #> 2 POLYGON ((3 2, 3 3, 4 3, 4 ...
    

    【讨论】:

      猜你喜欢
      • 2017-07-05
      • 2016-02-03
      • 2012-03-13
      • 2013-10-16
      • 2016-11-18
      • 2015-09-06
      • 2020-02-23
      • 2010-12-19
      • 1970-01-01
      相关资源
      最近更新 更多