Production-grade SSURGO queries: soil organic carbon, NCCPI, interpretations, dominant condition method, spatial AOI, KSSL lab SOC cascade, and SHAPE scoring groups. Seven advanced lessons.
The pattern used in 90% of production SSURGO scripts
Temp tables break complex SSURGO queries into stages: first gather the map units (#map), then the components (#comp), then the horizons (#horizon) — each step building on the last. CTEs achieve the same result and work in SDA.
The equation behind SSURGO's carbon accounting
SOC (g/m²) = ((Hz_cm × (OM/1.724 × Db)) / 100) × ((100 − frag%) / 100) × compPct × 100OM / 1.724 — converts organic matter % to organic carbon % (Van Bemmelen factor)× Db — bulk density (g/cc) converts concentration to mass per volume× Hz_cm — horizon thickness converts to depth-weighted stock× (1 − frag/100) — rock fragment correction (soil only, not rocks)× comppct_r × 100 — component weighting for map unit proportional stockThe cointerp table: how SSURGO rates soil suitability
The cointerp table stores interpretation ratings for each component. Key fields: mrulename (the rule, e.g., "Fragile Soil Index"), ruledepth (0=top-level, 1=sub-rule), interphrc (rating class), interphr (numeric 0–1).
ruledepth = 0 for the overall top-level rating. Use ruledepth = 1 for crop-specific sub-rules (e.g., NCCPI for corn vs. soybeans separately).Aggregating interpretations to the map unit level
The dominant condition method assigns a single rating class to a map unit based on which class covers the most component percent. This is the standard SSURGO aggregation used in the Regen Ag Risk Map and fragile soil mapping.
Pattern: GROUP BY mukey + interphrc, SUM comppct_r, pick the highest sum with ROW_NUMBER().
Constraining queries to a geographic polygon
The SDA spatial endpoint accepts a WKT geometry to return only map units that intersect an area of interest. This enables field-level, county-level, and custom boundary queries without pre-filtering by areasymbol.
How DSPHub estimates soil organic carbon when measurements vary
The Kellogg Soil Survey Laboratory (KSSL) doesn't always have the same measurements for every pedon. DSPHub solves this with a prioritized cascade: use the best available method, fall through to the next when data is missing.
estimated_organic_carbon — Direct KSSL estimate (best)total_carbon_ncs − (caco3_lt_2_mm × 0.12) — Subtract inorganic CaCO₃total_carbon_ncs — Use total C when no CaCO₃ data0.25 + organic_carbon_walkley_black × 0.86 — Walkley-Black correctionThis cascade appears in DSPHub's Top Combined Estimated Organic Carbon.sql and is the same logic SHAPE uses to derive soil organic carbon from KSSL data.
Classifying soils so the right SHAPE curve applies
SHAPE doesn't use one universal curve. Before scoring, every soil is classified into a texture group (T1–T5) based on surface texture and a suborder group (S1–S5) based on taxonomic suborder. These two axes select the right benchmark for that soil type.
Source: DSPHub / DSP_Point_SDA_intersect.sql ↗ — the full version uses spatial geometry to find the map unit at a point, then derives T and S groups.
Now automate everything — call SDA from Python or JavaScript, build analysis pipelines, and connect soil data to interactive maps.