intersect {raster}R Documentation

Intersect

Description

Extent objects: Returns the intersection, i.e. the area of overlap of two Extent objects. The second argument can also be any argument from which an Extent object can be extracted.

If the first object is a Raster* object: this function is equivalent to 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.

Usage

## S4 method for signature 'Extent,ANY'
intersect(x, y)

## S4 method for signature 'Raster,ANY'
intersect(x, y)

## S4 method for signature 'SpatialPolygons,SpatialPolygons'
intersect(x, y)

## S4 method for signature 'SpatialPoints,ANY'
intersect(x, y)

## S4 method for signature 'SpatialPoints,Raster'
intersect(x, y)

## S4 method for signature 'SpatialPoints,SpatialPolygons'
intersect(x, y)

Arguments

x

Extent, Raster*, SpatialPolygons* or SpatialPoints* object

y

same as 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 extracted

Value

Extent, Raster*, or SpatialPolygons object

See Also

union, extent, crop

Examples

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)
}

[Package raster version 2.3-12 Index]