Learn R Programming

raster (version 2.3-40)

intersect: 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

## 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 'SpatialLines,SpatialPolygons':
intersect(x, y)

## S3 method for class 'SpatialPoints,SpatialPolygons':
intersect(x, y)

## S3 method for class 'SpatialVector,ANY':
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

Run this code
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