add_neighbour: Add isolated areas (polygons) to its nearest neighbour

View source: R/add_neighbour.R

add_neighbourR Documentation

Add isolated areas (polygons) to its nearest neighbour

Description

The function returns a neighbour list of class nb and its associated spatial adjacency matrix computed by adding isolated areas to its nearest neighbour (in terms of Euclidean distance between centroids) using the knearneigh function of 'spdep' package.

Usage

add_neighbour(carto, nb = NULL, plot = FALSE)

Arguments

carto

object of class SpatialPolygonsDataFrame or sf.

nb

optional argument with the neighbour list of class nb. If NULL (default), this object is computed from the carto argument.

plot

logical value (default FALSE), if TRUE then the computed neighbourhood graph is plotted.

Value

This function returns a list with the following two elements:

  • nb: the modified neighbours's list

  • W: associated spatial adjacency matrix of class dgCMatrix

Examples

library(spdep)

## Load the Spanish colorectal cancer mortality data ##
data(Carto_SpainMUN)

## Compute the neighbour list from spatial polygons ##
nb_SpainMUN <- poly2nb(Carto_SpainMUN)
summary(nb_SpainMUN) # 1 region with no links

## Add isolated area to its nearest neighbour ####
carto.mod <- add_neighbour(carto=Carto_SpainMUN, nb=nb_SpainMUN)
summary(carto.mod$nb) # 0 region with no links


spatialstatisticsupna/bigDM documentation built on Aug. 22, 2024, 12:35 p.m.