Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

intersect

Intersect


Description

It depends on the classes of the x and y what is returned.

If x is a Raster* object the extent of y is used, irrespective of the class of y, and a Raster* is returned. This is equivalent to crop.

If x is a Spatial* object, a new Spatial* object is returned. If x or y has a data.frame, these are also returned (after merging if necessary) as part of a Spatial*DataFrame, and this is how intersect is different from rgeos::gIntersection on which it depends.

Intersecting SpatialPoints* with SpatialPoints* uses the extent (bounding box) of y to get the intersection. Intersecting of SpatialPoints* and SpatialLines* is not supported because of numerical inaccuracies with that. You can use buffer, to create SpatialPoygons* from SpatialLines* and use that in intersect. Or try gIntersection.

Usage

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

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

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

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

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

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

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

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

Arguments

x

Extent, Raster*, SpatialPolygons*, SpatialLines* or SpatialPoints* object

y

same as for x

Value

if x is an Extent object: Extent

if x is a Raster* object: Raster*

if x is a SpatialPoints* object: SpatialPoints*

if x is a SpatialPolygons* object: SpatialPolygons*

if x is a SpatialLines* object and if y is a SpatialLines* object: SpatialPoints*

if x is a SpatialLines* object and if y is a SpatialPolygons* object: SpatialLines*

See Also

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

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.