# NOT RUN {
m1a <- matrix(c(17.5, 24.7, 22.6, 16.5, 55.1, 55.0, 61.1, 59.7), nrow = 4, ncol = 2)
m1b <- m1a
m1b[, 1] <- m1b[, 1] + 11
p1 <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(m1a, FALSE),
sp::Polygon(m1b, FALSE)), 1)))
sp::plot(p1, col = "blue")
m2a <- matrix(c(19.6, 35.7, 28.2, 60.0, 58.8, 64.4), nrow = 3, ncol = 2)
m2b <- matrix(c(20.6, 30.9, 27.3, 56.2, 53.8, 51.4), nrow = 3, ncol = 2)
p2 <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(m2a, FALSE),
sp::Polygon(m2b, FALSE)), 2)))
sp::plot(p2, col = "red", add = TRUE)
p <- SetPolygons(p1, p2, "gIntersection")
sp::plot(p, col = "green", add = TRUE)
p <- SetPolygons(p2, p1, "gDifference")
sp::plot(p, col = "purple", add = TRUE)
# }
Run the code above in your browser using DataLab