erase: Erase parts of a SpatialPolygons* or SpatialLines* object....

Description Usage Arguments Value See Also Examples

Description

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

Usage

1
2
3
4
5
## 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
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)
}

Example output

Loading required package: sp
Loading required package: rgdal
Loading required package: rgeos
Warning messages:
1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called 'rgdal'
2: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called 'rgeos'

raster documentation built on Jan. 5, 2021, 3:01 a.m.