Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

get_adjacencies

get_adjacencies


Description

Fast calculation of adjacencies between classes in a raster

Usage

get_adjacencies(landscape, neighbourhood, what, upper)

## S3 method for class 'RasterLayer'
get_adjacencies(landscape, neighbourhood = 4, what = "full", upper = FALSE)

## S3 method for class 'RasterStack'
get_adjacencies(landscape, neighbourhood = 4, what = "full", upper = FALSE)

## S3 method for class 'RasterBrick'
get_adjacencies(landscape, neighbourhood = 4, what = "full", upper = FALSE)

## S3 method for class 'stars'
get_adjacencies(landscape, neighbourhood = 4, what = "full", upper = FALSE)

## S3 method for class 'list'
get_adjacencies(landscape, neighbourhood = 4, what = "full", upper = FALSE)

## S3 method for class 'matrix'
get_adjacencies(landscape, neighbourhood = 4, what = "full", upper = FALSE)

Arguments

landscape

Raster* Layer, Stack, Brick, SpatRaster (terra), stars, or a list of rasterLayers.

neighbourhood

The number of directions in which cell adjacencies are considered as neighbours: 4 (rook's case), 8 (queen's case) or a binary matrix where the ones define the neighbourhood. The default is 4.

what

Which adjacencies to calculate: "full" for a full adjacency matrix, "like" for the diagonal, "unlike" for the off diagonal part of the matrix and "triangle" for a triangular matrix counting adjacencies only once.

upper

Logical value indicating whether the upper triangle of the adjacency matrix should be returned (default FALSE).

Details

A fast implementation with Rcpp to calculate the adjacency matrix for raster. The adjacency matrix is most often used in landscape metrics to describe the configuration of landscapes, is it is a cellwise count of edges between classes.

The "full" adjacency matrix is double-count method, as it contains the pairwise counts of cells between all classes. The diagonal of this matrix contains the like adjacencies, a count for how many edges a shared in each class with the same class.

The "unlike" adjacencies are counting the cellwise edges between different classes.

Value

matrix with adjacencies between classes in a raster and between cells from the same class.

Examples

# calculate full adjacency matrix
get_adjacencies(landscape, 4)

# count diagonal neighbour adjacencies
diagonal_matrix <- matrix(c(1,  NA,  1,
                            NA,  0, NA,
                            1,  NA,  1), 3, 3, byrow = TRUE)
get_adjacencies(landscape, diagonal_matrix)

# equivalent with the raster package:
adjacencies <- raster::adjacent(landscape, 1:raster::ncell(landscape), 4, pairs=TRUE)
table(landscape[adjacencies[,1]], landscape[adjacencies[,2]])

landscapemetrics

Landscape Metrics for Categorical Map Patterns

v1.5.2
GPL-3
Authors
Maximillian H.K. Hesselbarth [aut, cre] (<https://orcid.org/0000-0003-1125-9918>), Marco Sciaini [aut] (<https://orcid.org/0000-0002-3042-5435>), Jakub Nowosad [aut] (<https://orcid.org/0000-0002-1057-3721>), Sebastian Hanss [aut] (<https://orcid.org/0000-0002-3990-4897>), Laura J. Graham [ctb] (Input on package structure), Jeffrey Hollister [ctb] (Input on package structure), Kimberly A. With [ctb] (Input on package structure), Florian Privé [ctb] (Original author of underlying C++ code for get_nearestneighbour() function), Project Nayuki [ctb] (Original author of underlying C++ code for get_circumscribingcircle and lsm_p_circle), Matt Strimas-Mackey [ctb] (Bugfix in sample_metrics())
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.