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

union

Union Extent or SpatialPolygons* objects


Description

Extent objects: Objects are combined into their union. See crop and extend to union a Raster object with an Extent object.

Two SpatialPolygons* objects. Overlapping polygons (between layers, not within layers) are intersected, other spatial objects are appended. Tabular attributes are joined. See bind if you want to combine polygons without intersection.

Single SpatialPolygons* object. Overlapping polygons are intersected. Original attributes are lost. New attributes allow for determining how many, and which, polygons overlapped.

Union for SpatialLines and SpatialPoints simply combines the two data sets; without any geometric intersections. This is equivalent to bind.

Usage

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

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

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

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

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

Arguments

x

Extent or SpatialPolygons* object

y

Same as x or missing

Value

Extent or SpatialPolygons object

See Also

merge for merging a data.frame with attributes of Spatial objects and +,SpatialPolygons,SpatialPolygons-method for an algebraic notation

Examples

e1 <- extent(-10, 10, -20, 20)
e2 <- extent(0, 20, -40, 5)
union(e1, e2)

#SpatialPolygons
if (require(rgdal) & require(rgeos)) {
	p <- shapefile(system.file("external/lux.shp", package="raster"))
	p0 <- aggregate(p)
	b <- as(extent(6, 6.4, 49.75, 50), 'SpatialPolygons')
	crs(b) <- crs(p)
	u <- union(p0, b)
	plot(u, col=2:4)
}

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.