
Fill missing horizon attributes from a SoilGrids depth prior
Source:R/soilgrids-depth-fill.R
apply_soilgrids_depth_prior.RdFor each horizon and each requested attribute, interpolates the value
at the horizon's mid-depth from the six standard SoilGrids 2.0 depth
slices (0-5, 5-15, 15-30, 30-60, 60-100, 100-200 cm) and writes it
into the pedon with source = "inferred_prior". Existing values
are preserved unless overwrite = TRUE; the
PedonRecord authority order means a SoilGrids prior can
never silently displace a measured, spectra-predicted or VLM-extracted
value.
Arguments
- pedon
A
PedonRecordwith at least one horizon. For the live fetch it must also carrysite$latandsite$lon.- attrs
Character vector of horizon columns to fill. Defaults to all SoilGrids-backed attributes:
clay_pct,sand_pct,silt_pct,ph_h2o,oc_pct,cec_cmol.- depth_profiles
Optional named list mapping an attribute to a numeric vector of six slice values (0-5 ... 100-200 cm). When supplied the SoilGrids network call is skipped entirely – this is the path the test suite and offline users take.
- overwrite
If
FALSE(default) onlyNAcells are filled. IfTRUE, every requested cell is overwritten (subject to the provenance authority order).
Value
Invisibly, the mutated pedon. An attribute
"soilgrids_depth_fill" on the return value records how
many cells were filled.
Details
This is the depth-resolved companion to
spatial_prior_soilgrids (which returns a site-level RSG
probability vector, not horizon attributes), and the attribute-fill
stage of classify_from_photos.
Examples
if (FALSE) { # \dontrun{
p <- make_cambisol_canonical()
p$horizons$clay_pct <- NA_real_
# Offline: supply the six-slice profiles directly.
apply_soilgrids_depth_prior(
p, attrs = "clay_pct",
depth_profiles = list(clay_pct = c(18, 20, 24, 28, 30, 30)))
} # }