get_adjacent {flexurba} | R Documentation |
Identify adjacent cells
Description
The function identifies all cells that are adjacent to non-NA
cells in x
. The implementation of the function relies on the function terra::adjacent()
.
Usage
get_adjacent(
x,
cells = "all",
adjacent_value = 1,
include = TRUE,
directions = 8
)
Arguments
x |
SpatRaster |
cells |
character / integer. Either |
adjacent_value |
integer. Value assigned to adjacent cells in the resulting grid |
include |
logical. Whether to include the focal cells in the resulting grid |
directions |
integer. Which cells are considered adjacent: |
Value
SpatRaster with adjacent cells
Examples
set.seed(10)
nr <- nc <- 10
r <- terra::rast(
ncols = nc, nrows = nr,
ext = c(0, nc, 0, nr),
vals = sample(c(NA, 1, 2), nr * nc, replace = TRUE, prob = c(0.8, 0.1, 0.1))
)
terra::plot(r)
adj1 <- get_adjacent(r)
terra::plot(adj1)
adj2 <- get_adjacent(r, cells = 1, include = FALSE)
terra::plot(adj2)
[Package flexurba version 0.2.2 Index]