【发布时间】:2016-07-31 17:48:41
【问题描述】:
我正在尝试从两个 sp 几何图形中的 gDifference 创建一组新的 SpatialPoints。假设如下:
你有两个SpatialPolygons:
library(rgeos)
library(sp)
#Create SpatialPlygons objects
polygon1 <- readWKT("POLYGON((-190 -50, -200 -10, -110 20, -190 -50))")
#polygon 1
polygon2 <- readWKT("POLYGON((-180 -20, -140 55, 10 0, -140 -60, -180 -20))") #polygon 2
#Plot both polygons
par(mfrow = c(1,2)) #in separate windows
plot(polygon1, main = "Polygon1") #window 1
plot(polygon2, main = "Polygon2") #window 2
现在,你想得到它们之间的gDifference:
polygon_set <- readWKT(paste("POLYGON((-180 -20, -140 55, 10 0, -140 -60, -180 -20),",
"(-190 -50, -200 -10, -110 20, -190 -50))"))
par(mfrow = c(1,1)) #now, simultaneously
plot(polygon_set, main = "Polygon1 & Polygon2")
clip <- gDifference(polygon2, polygon1, byid = TRUE, drop_lower_td = T) #clip polygon 2 with polygon 1
plot(clip, col = "red", add = T)
我怎样才能得到一个只有polygon2 的非相交点的sp 几何图形(即下图中的红点)?
提前致谢!
【问题讨论】:
-
把它们变成单独的线并测试相交然后选择那些不相交的?
-
我已经尝试过了,但返回了整个
polygon2。我假设它只在整条线被“包含”时才考虑交集 -
determine the points of intersection 之后,您需要确定生成所需多边形的顺序。调整顺序后,
ggplot2::fortify函数将提供一个不错的 data.frame 供您在绘图中使用。