Setup

# stable packages from CRAN
install.packages('igraph')
install.packages('soilDB')
install.packages('sharpshootR')
install.packages('sf')
install.packages('spdep')

# latest versions from GitHub
remotes::install_github("ncss-tech/soilDB", dependencies=FALSE, upgrade_dependencies=FALSE)
remotes::install_github("ncss-tech/sharpshootR", dependencies=FALSE, upgrade_dependencies=FALSE)

Linework Evaluation

library(soilDB)
library(sharpshootR)
library(sf)
library(spdep)
library(lattice)
library(igraph)

# example point, WGS84 coordinates
p <- st_as_sf(data.frame(x = -83.45657,
                         y = 35.04229),
              coords = c('x', 'y'),
              crs = 4326)

# 2km buffer applied to point defined in geographic coordinates
b <- st_buffer(p, dist = units::set_units(2000, m))

# result is an sf object
x <- SDA_spatialQuery(b, what = 'mupolygon', byFeature = TRUE, geomIntersection = TRUE)
# look up map unit symbols for these map unity keys
.is <- format_SQL_in_statement(x$mukey)
.sql <- sprintf("SELECT mukey, musym FROM mapunit WHERE mukey IN %s", .is)
mu <- SDA_query(.sql)

x <- merge(x, mu, by = 'mukey')

# check: OK
plot(x['musym'])

# create polygon adjacency matrix
res <- polygonAdjacency(x, v = 'musym')
# plot spatial adjacency information
par(mar = c(0, 0, 0, 0))
plotSoilRelationGraph(res$adjMat, vertex.scaling.factor = 1)

plotSoilRelationGraph(res$adjMat, spanning.tree = 0.9, edge.scaling.factor = 0.5)

plotSoilRelationGraph(res$adjMat, spanning.tree = 'max', edge.scaling.factor = 0.5, vertex.scaling.factor = 1.5)


This document is based on aqp version 2.0, soilDB version 2.7.6, and sharpshootR version 2.0.