I am trying to create a new set of SpatialPoints
from the gDifference
of two sp
geometries. Suppose the following:
You have two 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
Now, you want to get the gDifference
between them:
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)
How can I get a sp
geometry with only the non-intersecting points of the polygon2
(i.e., the red points in the following image)?
Thanks in advance!