terra (version 1.0-10)

boundaries: Detect boundaries (edges)

Description

Detect boundaries (edges). boundaries 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

# S4 method for SpatRaster
boundaries(x, classes=FALSE, type="inner", 
         directions=8, filename="", overwrite=FALSE, wopt=list(), ...)

Arguments

x

SpatRaster

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)

filename

character. Output filename. Optional

overwrite

logical. If TRUE, filename is overwritten

wopt

list. Options for writing files as in writeRaster

...

additional arguments. None implemented

Value

SpatRaster. Cell values are either 1 (a border) or 0 (not a border), or NA

See Also

focal, clump

Examples

Run this code
# NOT RUN {
r <- rast(nrow=18, ncol=36, xmin=0)
v <- rep(NA, ncell(r))
v[150:250] <- 1
v[251:450] <- 2
values(r) <- v
bi <- boundaries(r, type="inner")
bo <- boundaries(r, type="outer")
bc <- boundaries(r, classes=TRUE)
plot(bc)
# }

Run the code above in your browser using DataLab