1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
\name{erase}
\docType{methods}
\alias{erase}
\alias{erase,SpatialPolygons,SpatialPolygons-method}
\alias{erase,SpatialLines,SpatialPolygons-method}
\title{
Erase parts of a SpatialPolygons* or SpatialLines* object. The inverse of this can be done with \code{\link{intersect}}
}
\description{
Erase parts of a SpatialPolygons* or SpatialLines* object with a SpatialPolygons* object
}
\usage{
\S4method{erase}{SpatialPolygons,SpatialPolygons}(x, y, ...)
\S4method{erase}{SpatialLines,SpatialPolygons}(x, y, ...)
}
\arguments{
\item{x}{SpatialPolygons or SpatialLines object}
\item{y}{SpatialPolygons object}
\item{...}{Additional arguments (none)}
}
\value{
Spatial*
}
\seealso{The equivalent for raster data is \code{\link{mask}}}
\examples{
# 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)
}
\keyword{methods}
\keyword{spatial}
|