ngb8: Eight neighbors

View source: R/ngb8.R

ngb8R Documentation

Eight neighbors

Description

Return the 8 neighbors, as cell numbers, of each cell on a raster.

Usage

ngb8(n_row, n_col)

Arguments

n_row

Integer. The number of rows of a Raster or object.

n_col

Integer. The number of columns of a Raster object.

Details

A cell with coordinates (x, y) has 8 neighbors with coordinates: (x±1, y), (x, y±1) and (x±1, y±1). Cells on the edge of a raster have less than 8 neighbors. The function identifies the neighbors of a cell as cell numbers.

Value

Named list, the nth element of the list corresponds to the 8 adjacent cell numbers of the nth cell on the Raster* object.

See Also

ngbList()

Examples

## Matrix m mocking a raster of 3 rows and 4 columns
m <- matrix(1:12, nrow = 3, ncol = 4, byrow = TRUE)
m

nbs <- ngb8(3, 4)
nbs

scapesClassification documentation built on March 18, 2022, 6:32 p.m.