Description Usage Arguments Details Value Author(s) Examples
Perform set operations such as intersections and unions on two parallel SpatialPolygons objects. Requires installation of the rgeos package.
1 2 3 4 5 6 7 8 | ## S4 method for signature 'SpatialPolygons,SpatialPolygons'
pintersect(x, y)
## S4 method for signature 'SpatialPolygons,SpatialPolygons'
punion(x, y)
## S4 method for signature 'SpatialPolygons,SpatialPolygons'
psetdiff(x, y)
|
x, y |
SpatialPolygons objects to be processed in parallel. The shorter object is recycled to the same length as the larger object. |
These functions iterate through x
and y
simultaneously to take the intersection, union, etc.
of the corresponding polygons in the two objects.
If the intersection is empty, a polygon is returned with zero area and all vertices at the origin. This is necessary because, unfortunately, the Polygons constructor does not support empty lists.
Lines or points formed by intersections are currently ignored.
A SpatialPolygons object representing the intersection, union or difference of the polygons.
Aaron Lun
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | poly <- makeSpatialPolygons(
rbind(c(0,0), c(0.5, 0), c(0.5, 0.5), c(0, 0.5)),
rbind(c(1,1), c(0.5, 1), c(0.5, 0.5), c(1, 0.5)),
rbind(c(0.5,0), c(1, 0), c(1, 0.5), c(0.5, 0.5)),
rbind(c(0,1), c(0.5, 1), c(0.5, 0.5), c(0, 0.5))
)
plot(poly)
other.poly <- makeSpatialPolygons(
rbind(c(0.1,0.1), c(0.7, 0.1), c(0.7, 0.7), c(0.1, 0.7))
)
intersected <- pintersect(poly, other.poly)
plot(intersected[1], xlim=c(0, 1), ylim=c(0, 1))
unioned <- punion(poly, other.poly)
plot(unioned[1], xlim=c(0, 1), ylim=c(0, 1))
diffed <- psetdiff(poly, other.poly)
plot(diffed[1], xlim=c(0, 1), ylim=c(0, 1))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.