raster (version 2.1-41)

edge: Edge detection

Description

Detect edges. Edges are cells that have more than one class in the 4 or 8 cells surrounding it, or, if classes=FALSE, cells with values and cells with NA.

Usage

## S3 method for class 'RasterLayer':
edge(x, filename="", type='inner', classes=FALSE, directions=8, ...)

Arguments

x
RasterLayer object
filename
Character. Filename for the output RasterLayer (optional)
type
Character. 'inner', or 'outer'
classes
Character. Logical. If TRUE all different values are (after rounding) distinguished, as well as NA. If FALSE (the default) only edges between NA and non-NA cells are considered
directions
Integer. Which cells are considered adjacent? Should be 8 (Queen's case) or 4 (Rook's case)
...
Additional arguments as for writeRaster

Value

  • RasterLayer. Cell values are either 1 (and edge) or 0 (not an edge), or NA

See Also

focal, clump

Examples

Run this code
r <- raster(nrow=18, ncol=36, xmn=0)
r[150:250] <- 1
r[251:450] <- 2
plot( edge(r, type='inner') )
plot( edge(r, type='outer') )
plot( edge(r, classes=TRUE) )

Run the code above in your browser using DataLab