Learn R Programming

scapesClassification (version 1.0.0)

ngb8: 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.

Value

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

Details

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

See Also

ngbList()

Examples

Run this code
# NOT RUN {
## 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
# }

Run the code above in your browser using DataLab