Dylan Beaudette (USDA-NRCS Sonora, CA)
October 7, 2014
This document is based on aqp
version 1.7-6, soilDB
version 1.3-5, and sharpshootR
version 0.6-7.
# install stable versions
install.packages('aqp', dep=TRUE)
install.packages('soilDB', dep=TRUE)
install.packages('sharpshootR', dep=TRUE)
# install latest versions from R-Forge:
install.packages('aqp', repos="http://R-Forge.R-project.org", type='source')
install.packages('soilDB', repos="http://R-Forge.R-project.org", type='source')
install.packages('sharpshootR', repos="http://R-Forge.R-project.org", type='source')
# load libraries
library(aqp)
library(soilDB)
library(sharpshootR)
library(lattice)
library(plyr)
library(Hmisc)
# set options
options(width=100, stringsAsFactors=FALSE)
repeatable, self-documenting work:
algorithm development by experts, application by trained users
AQP family of packages
aqp
soilDB
sharpshootR
Examples
Details on numerical classification algorithm (?)
Live demo (?)
a “vocabulary” for soil data analysis
access to soil data should be simple, often it is not
# soilDB one-liners
auburn.lab <- fetchKSSL("auburn") # KSSL data
auburn.extent <- seriesExtent("auburn") # SSURGO-based series extent map
auburn.compdata <- SDA_query("<SQL>") # SSURGO-based tabular data
custom datatype to store/access hierarchy of soil profile information
# sample dataset, extracted from NASIS
library(soilDB)
data(loafercreek)
str(loafercreek, 2)
Formal class 'SoilProfileCollection' [package "aqp"] with 7 slots
..@ idcol : chr "peiid"
..@ depthcols : chr [1:2] "hzdept" "hzdepb"
..@ metadata :'data.frame': 1 obs. of 1 variable:
..@ horizons :'data.frame': 308 obs. of 34 variables:
..@ site :'data.frame': 54 obs. of 59 variables:
..@ sp :Formal class 'SpatialPoints' [package "sp"] with 3 slots
..@ diagnostic:'data.frame': 177 obs. of 4 variables:
Typical pedon/site data:
id, top, bottom, name, group
1, 0, 10, A, g1
1, 10, 18, AB, g1
...
2, 12, 22, E, g2
2, 22, 45, Bhs1, g2
Converting data.frame
→ SoilProfileCollection
:
x <- read.csv(file = ...)
# promote to SoilProfileCollection
depths(x) <- id ~ top + bottom
# move 'site data' into @site
site(x) <- ~group
Functions that return SoilProfileCollection
:
x <- fetchOSD()
x <- fetchKSSL()
x <- fetchPedonPC()
x <- fetchNASIS()
x <- fetchNASIS_component_data()
idname(sp4) # pedon ID name
horizonDepths(sp4) # colum names containing top and bottom depths
depth_units(sp4) # defaults to 'cm'
metadata(sp4) # data.frame with 1 row
profile_id(sp4) # vector of profile IDs
length(sp4) # number of profiles in the collection
nrow(sp4) # number of horizons in the collection
names(sp4) # column names from site and horizon data
min(sp4) # shallowest profile depth in collection
max(sp4) # deepest profile depth in collection
sp4[i, j] # get profile "i", horizon "j"
horizons(sp4) # get / set horizon data
site(sp4) # get / set site data
diagnostic_hz(sp4) # get / set diagnostic horizons
proj4string(sp4) # get / set CRS
coordinates(sp4) # get / set coordinates
SpatialPointsDataFrame
or data.frame
as(sp4, 'SpatialPointsDataFrame')
as(sp4, 'data.frame')
flexible generation of soil profile sketches using “base graphics”