% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/spatial-soilgrids.R
\name{spatial_prior_soilgrids}
\alias{spatial_prior_soilgrids}
\title{SoilGrids spatial prior}
\usage{
spatial_prior_soilgrids(
  pedon,
  system = c("wrb2022", "usda"),
  buffer_m = 250,
  source_url = NULL,
  n_classes_top = 10,
  lut = NULL,
  ...
)
}
\arguments{
\item{pedon}{A \code{\link{PedonRecord}} with non-NULL
\code{site$lat} and \code{site$lon}.}

\item{system}{Classification system; \code{"wrb2022"} (default) maps
SoilGrids integer codes through the WRB lookup table.
\code{"usda"} is reserved for a future SoilGrids-USDA layer.}

\item{buffer_m}{Buffer radius in metres around the point (default
250 m, i.e. one SoilGrids pixel).}

\item{source_url}{Optional. A path or URL accepted by
\code{terra::rast}. If NULL, falls back to
\code{getOption("soilKey.test_raster")}.}

\item{n_classes_top}{Keep only the top N classes by frequency
(default 10). Set to \code{Inf} to keep all.}

\item{lut}{Optional named integer vector mapping raster values to
RSG codes. Default is \code{\link{soilgrids_wrb_lut}}; pass
a custom one if your raster uses different codes.}

\item{...}{Reserved for future use.}
}
\value{
A \code{data.table} with columns \code{rsg_code},
        \code{probability}.
}
\description{
Reads a categorical raster of dominant Reference Soil Groups around
the pedon's site, buffers the point in metric coordinates, extracts
all pixel values within the buffer, and returns the empirical class
frequency as a probability distribution over RSG codes.
}
\section{Data source}{

For real use, pass \code{source_url} pointing at a SoilGrids
"MostProbable WRB" GeoTIFF / COG, e.g. one of the regional cuts
published at \code{https://files.isric.org/soilgrids/latest/data/wrb/}.
For tests, set \code{options(soilKey.test_raster = "/path/to/syn.tif")}
to point at a local synthetic raster -- this avoids network access
in CI.
}

\section{Coordinate handling}{

We use \code{sf::st_transform} when sf is available; otherwise we
fall back to \code{terra::project} on a single-point SpatVector.
The buffer is constructed in metric (UTM) coordinates so
\code{buffer_m} is in metres regardless of the pedon CRS. The
raster itself is queried in its native CRS via terra's automatic
reprojection.
}

\seealso{
\code{\link{spatial_prior}}, \code{\link{soilgrids_wrb_lut}}.
}
