gIntersection {rgeos} | R Documentation |
Function for determining the intersection between the two given geometries
gIntersection(spgeom1, spgeom2, byid=FALSE, id=NULL)
spgeom1, spgeom2 |
sp objects as defined in package sp |
byid |
Logical vector determining if the function should be applied across ids (TRUE) or the entire object (FALSE) for spgeom1 and spgeom2 |
id |
Character vector defining id labels for the resulting geometries, if unspecified returned geometries will be labeled based on their parent geometries' labels. |
Returns all spatial intersections as sp objects of the appropriate class. If the geometries do not intersect then an empty geometry is returned.
Roger Bivand & Colin Rundel
gDifference
gSymdifference
gUnion
library(maptools) xx <- readShapeSpatial(system.file("shapes/fylk-val-ll.shp", package="maptools")[1], proj4string=CRS("+proj=longlat +datum=WGS84")) bbxx <- bbox(xx) wdb_lines <- system.file("share/wdb_borders_c.b", package="maptools") xxx <- Rgshhs(wdb_lines, xlim=bbxx[1,], ylim=bbxx[2,])$SP res <-gIntersection(xx, xxx) plot(xx, axes=TRUE) plot(xxx, lty=2, add=TRUE) plot(res, add=TRUE, pch=16,col='red')