Learn R Programming

sharpshootR (version 1.5)

polygonAdjacency: Evaluate Spatial Adjacency of SpaitialPolygonsDataFrame Objects

Description

This function utilizes the `spdep` and `igraph` packages to evaluate several measures of spatial connectivity.

Usage

polygonAdjacency(x, v='MUSYM', ...)

Arguments

x

a SpatialPolygonsDataFrame object

v

name of the field in the attribute table to use when searching for `common lines`, see details

additional arguments passed to spdep::poly2nb

Value

A list object containing:

commonLines

An integer vector of feature IDs, that share a common boundary and attribute v.commonLines. Sometimes referred to as "common soil lines".

adjMat

A weighted adjacency matrix

Details

Pending.

Examples

Run this code
# NOT RUN {
library(spdep)
library(rgdal)
library(igraph)
library(sharpshootR)

# load some data
x <- readOGR(dsn='L:/CA630/FG_CA630_OFFICIAL.gdb', layer='ca630_a', stringsAsFactors=FALSE)

# remove NOTCOM, DA, and empty (non-NA) symbols
x <- x[which(! x$MUSYM %in% c('NOTCOM', 'DA', ' ', '')), ]

# compute spatial adjacency summary
res <- polygonAdjacency(x, v='MUSYM')

# graphical check: slow for large number of features
plot(x)
plot(x[res$commonLines, ], col='red', add=TRUE)

# save to SHP
writeOGR(x[res$commonLines, ], dsn='.', 
layer='common-soil-lines', driver='ESRI Shapefile', 
overwrite_layer=TRUE)

# plot spatial adjacency information
par(mar=c(0,0,0,0))

# full adjacency graph: very messy
plotSoilRelationGraph(res$adjMat, 
vertex.scaling.factor = 1, vertex.label.family='sans',
vertex.label.cex=0.75,
g.layout = layout_with_lgl)

# trim down via "max spanning tree"
plotSoilRelationGraph(res$adjMat, spanning.tree='max', 
edge.scaling.factor=0.1, vertex.scaling.factor=1, 
vertex.label.family='sans',
vertex.label.cex=0.75,
g.layout = layout_with_lgl)

# get the resulting graph for later inspection
g <- plotSoilRelationGraph(res$adjMat, spanning.tree='max', 
edge.scaling.factor=0.1, vertex.scaling.factor=1, 
vertex.label.family='sans',
vertex.label.cex=0.75,
g.layout = layout_with_lgl)

# get vertices that are neighbors with a given vertex
neighbors(g, '9012')

# plot subgraph
plot(subgraph(g, neighbors(g, '9012')), 
vertex.label.family='sans',
vertex.label.cex=0.75,
layout=layout_with_lgl)
# }
# NOT RUN {

# }

Run the code above in your browser using DataLab