polygonNeighbors: Find the neighboring regions of each region in a shapefile.

Description Usage Arguments Value Examples

View source: R/polygonNeighbors.R

Description

Find the neighboring regions of each region in a shapefile. Outputs a dataframe with each region and optionally a matrix and plot of adjacencies.

Usage

1
polygonNeighbors(shp, id = NULL, nb.matrix = FALSE, plot = FALSE)

Arguments

shp

A SpatialPolygonsDataFrame

id

The name of the variable in [email protected] to find adjacencies for.

nb.matrix

Whether to output the adjacency matrix as well.

plot

Whether to plot the adjacencies (for checking).

Value

Returns a list with a data.frame of each adjacency and optionally the adjacency matrix and/or a plot of the adjacencies.

Examples

1
2
3
4
5
6
7
8
# Get a shapefile of US States:
file <- "http://www2.census.gov/geo/tiger/GENZ2015/shp/cb_2015_us_state_20m.zip"
download.file(file, "states.zip")
unzip("states.zip")
shp <- rgdal::readOGR(".", "cb_2015_us_state_20m")
shp <- shp[!(shp@data$STATEFP %in% c("02", "15", "72")),]  # Contiguous US
shp <- sp::spTransform(shp, sp::CRS("+init=epsg:26978"))
state.adj <- polygonNeighbors(shp, id = "NAME", nb.matrix = TRUE, plot = TRUE)

walshc/polygonNeighbors documentation built on May 3, 2019, 11:51 p.m.