
crop
.
SpatialPolygons* objects: Only the overlapping areas (if any) are returned. For SpatialPolygonDataFrame objects, the data.frames are also merged.
SpatialPoints* objects: Only the points that overlap with the extent of object y
are returned.## S3 method for class 'Extent,ANY':
intersect(x, y)
## S3 method for class 'Raster,ANY':
intersect(x, y)
## S3 method for class 'SpatialPolygons,SpatialPolygons':
intersect(x, y)
## S3 method for class 'SpatialPoints,ANY':
intersect(x, y)
## S3 method for class 'SpatialPoints,Raster':
intersect(x, y)
## S3 method for class 'SpatialPoints,SpatialPolygons':
intersect(x, y)
x
. Except when x
is a Raster* or SpatialPoints* object, this should be an Extent object, or any object from which an Extent can be extractedunion, extent, crop
e1 <- extent(-10, 10, -20, 20)
e2 <- extent(0, 20, -40, 5)
intersect(e1, e2)
#SpatialPolygons
if (require(rgdal) & require(rgeos)) {
p <- shapefile(system.file("external/lux.shp", package="raster"))
b <- as(extent(6, 6.4, 49.75, 50), 'SpatialPolygons')
projection(b) <- projection(p)
i <- intersect(p, b)
plot(p)
plot(b, add=TRUE, col='red')
plot(i, add=TRUE, col='blue', lwd=2)
}
Run the code above in your browser using DataLab