Learn R Programming

fasterRaster (version 8.4.1.0)

neighborhoodMatrix,GVector-method: Neighborhood matrix from a polygons GVector

Description

This function returns a neighborhood matrix from a polygons GVector, which represents which geometries touch one another. It is useful for implementing geostatistical analyses that require indicators about which area features are next to one another.

Polygons must share more than one point for them to be considered a neighbors (i.e., same as spdep::poly2nb(x, queen = FALSE)).

This function needs the GRASS addon v.neighborhoodmatrix. If it is not installed, it will try to install it.

Usage

# S4 method for GVector
neighborhoodMatrix(x)

# S4 method for GVector neighbourhoodMatrix(x)

Value

A list. Each element represents a polygon. If an element is empty, it has no neighbors. Otherwise, it is a vector of integers, which represent the indices of the polygon(s) to which it is a neighbor.

Arguments

x

A polygons `GVector.

Examples

Run this code
if (grassStarted()) {

# Setup
library(sf)

# Polygons vector:
madCoast4 <- fastData(madCoast4)
mc4 <- fast(madCoast4)

neighs <- neighborhoodMatrix(mc4)
neighs

}

Run the code above in your browser using DataLab