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

erase

Erase parts of a SpatialPolygons* or SpatialLines* object. The inverse of this can be done with intersect


Description

Erase parts of a SpatialPolygons* or SpatialLines* object with a SpatialPolygons* object

Usage

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

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

Arguments

x

SpatialPolygons or SpatialLines object

y

SpatialPolygons object

...

Additional arguments (none)

Value

Spatial*

See Also

The equivalent for raster data is mask

Examples

if (require(rgdal) & require(rgeos)) {
# erase parts of polygons with other polygons
	p <- shapefile(system.file("external/lux.shp", package="raster"))
	b <- as(extent(6, 6.4, 49.75, 50), 'SpatialPolygons')
	crs(b) <- crs(p)
	e <- erase(p, b)
	plot(e)
	
	
# erase parts of lines with polygons	
	r <- raster(extent(p) +c(-.1,.1,-.1,.1), crs=crs(p))
	start <- xyFromCell(r, cellFromCol(r, 1))
	end <- xyFromCell(r, cellFromCol(r, ncol(r)))
	lines <- do.call(spLines, lapply(1:10, function(i)rbind(start[i,], end[i,])))
	crs(lines) <- crs(p)
	
	e2 <- erase(lines, p)
	plot(p)
	lines(lines, col='blue', lwd=4, lty=3)
	lines(e2, col='red', 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.