EXPERT SQL Track · 7 Lessons

Expert SQL
Track

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.

Lessons
01

Temp Tables — Multi-Step Queries

The pattern used in 90% of production SSURGO scripts

Expert

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.

Multi-Step Query as CTEs (SDA-Compatible) — ND001
02

Soil Organic Carbon — The Full Formula

The equation behind SSURGO's carbon accounting

Expert
SOC Formula: SOC (g/m²) = ((Hz_cm × (OM/1.724 × Db)) / 100) × ((100 − frag%) / 100) × compPct × 100
  • OM / 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 stock
Soil Organic Carbon by Horizon (0–100cm) — WI025
03

Interpretations — NCCPI & Fragile Soils

The cointerp table: how SSURGO rates soil suitability

Expert

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: Use ruledepth = 0 for the overall top-level rating. Use ruledepth = 1 for crop-specific sub-rules (e.g., NCCPI for corn vs. soybeans separately).
NCCPI + Fragile Soil Index — ND001
04

Dominant Condition Method

Aggregating interpretations to the map unit level

Expert

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().

Fragile Soil Index — Dominant Condition by Map Unit (IA025)
05

Spatial Queries — Area of Interest

Constraining queries to a geographic polygon

Expert

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.

Spatial endpoint: Full AOI geometry queries use the SDA Spatial endpoint and Tabular/post services together. The tabular example below shows the standard approach using areasymbol as a proxy for geographic filtering.
Multi-County Tabular Query (Spatial Approach via areasymbol)
For full spatial AOI workflows, see the Advanced Spatial Data Access PDF — the definitive guide to WKT geometry queries.
06

KSSL Lab SOC — The 4-Method Cascade

How DSPHub estimates soil organic carbon when measurements vary

Expert

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.

4-Method Priority:
  1. estimated_organic_carbon — Direct KSSL estimate (best)
  2. total_carbon_ncs − (caco3_lt_2_mm × 0.12) — Subtract inorganic CaCO₃
  3. total_carbon_ncs — Use total C when no CaCO₃ data
  4. 0.25 + organic_carbon_walkley_black × 0.86 — Walkley-Black correction

This 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.

KSSL SOC — 4-Method Cascade, Surface Horizon (Kansas) — DSPHub
Full DSPHub script with all KSSL characterization fields (texture, bulk density, CaCO₃, Walkley-Black, clay fractions): DSP_KSSL_SOC.sql ↗
07

SHAPE Scoring Groups — T1–T5 & S1–S5

Classifying soils so the right SHAPE curve applies

Expert

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.

Texture Groups: T1=Sandy · T2=Sandy Loam · T3=Silty · T4=Clay Loam · T5=Heavy Clay (>60%)
Suborder Groups: S1=Organic/Wet · S2=Aquic/Volcanic · S3=Mollisols/Spodosols · S4=Alfisols/Vertisols · S5=Arid/Erosional

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.

SHAPE T1–T5 Texture and S1–S5 Suborder Groups — WI025
Up Next

Take It to Code

Now automate everything — call SDA from Python or JavaScript, build analysis pipelines, and connect soil data to interactive maps.

Python API → JavaScript API →