terra (version 0.3-7)

adjacent: Adjacent cells

Description

Identify cells that are adjacent to a set of cells on a raster.

Usage

# S4 method for SpatRaster
adjacent(x, cells, directions, include, ...)

Arguments

x

SpatRaster

cells

vector of cell numbers for which adjacent cells should be found. Cell numbers start with 1 in the upper-left corner and increase from left to right and from top to bottom

directions

the directions in which cells should be connected: "rook" (4 directions), "queen" (8 directions), "16" (knight and one-cell queen moves), or "bishop" to connect cells with one-cell diagonal moves.

include

logical. Should the focal cells be included in the result?

...

additional arguments. None implemented

Value

vector with adjacent cells.

Examples

Run this code
# NOT RUN {
r <- rast(nrows=10, ncols=10)
adjacent(r, cells=c(1, 5, 55), directions="queen") 
r <- rast(nrows=10, ncols=10, crs="+proj=utm +zone=1 +datum=WGS84")
adjacent(r, cells=11, directions="rook") 
# global lat/lon wraps around
r <- rast(nrows=10, ncols=10, crs="+proj=longlat +datum=WGS84")
adjacent(r, cells=11, directions="rook") 
# }

Run the code above in your browser using DataLab