【发布时间】: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