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
.
# S4 method for SpatRaster
boundaries(x, classes=FALSE, type="inner",
directions=8, filename="", overwrite=FALSE, wopt=list(), ...)
SpatRaster
character. "inner" or "outer"
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
integer. Which cells are considered adjacent? Should be 8 (Queen's case) or 4 (Rook's case)
character. Output filename. Optional
logical. If TRUE
, filename
is overwritten
list. Options for writing files as in writeRaster
additional arguments. None implemented
SpatRaster. Cell values are either 1 (a border) or 0 (not a border), or NA
# 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