Linework Evaluation

library(spdep)
library(rgdal)
library(igraph)
library(sharpshootR)
library(lattice)

# load active survey
x <- readOGR(dsn='L:/NRCS/MLRAShared/CA630/FG_CA630_OFFICIAL.gdb', layer='ca630_a', stringsAsFactors=FALSE)
## OGR data source with driver: OpenFileGDB 
## Source: "L:/NRCS/MLRAShared/CA630/FG_CA630_OFFICIAL.gdb", layer: "ca630_a"
## with 6462 features
## It has 11 fields
# x <- readOGR(dsn='L:/NRCS/MLRAShared/CA792/ca792_spatial/FG_CA792_OFFICIAL.gdb', layer='ca792_a', stringsAsFactors=FALSE)

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

# create polygon adjacency matrix
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='l:/CA630/MapUnits', layer='common-soil-lines', driver='ESRI Shapefile', overwrite_layer=TRUE)
# plot spatial adjacency information
par(mar=c(0,0,0,0))
plotSoilRelationGraph(res$adjMat, vertex.scaling.factor = 1)