| metrics2Vol_spatial | R Documentation |
Compute tree-level SNFI volume variables while preserving plot geometry
This function mirrors the public arguments and calculations of
metrics2Vol but adds an optional spatial sidecar. The volume
computation itself is delegated to the original metrics2Vol(), so the
equation registry, fallback logic, provenance, units, and volume metadata
remain consistent with the non-spatial workflow.
Spatial information is prepared before the volume call by invoking
nfiMetrics_spatial() with spatial = "attribute" when the input is not
already an "nfiMetrics" object, and is copied back to the volume
output after metrics2Vol() finishes. Thus the geometry column never
travels through the volume-equation calculations. If spatial =
"sf", the function reconstructs an sf point object only at the end.
metrics2Vol_spatial(nfi,
cub.met = "freq",
parametro = c("VCC"),
keep.var = TRUE,
keep.legacy = FALSE,
method_registry = snfi_volume_method_registry(),
track_provenance = FALSE,
..., spatial = c("attribute",
"sf", "none",
"inherit"), var = c("d",
"h", "ba", "n",
"Hd", "Dd"),
levels = c("esta",
"espe"), design = snfi_design(),
domheight_method = "Hd",
domheight_registry = dominant_height_method_registry(),
geometry.dt.nm = NULL,
schema = NULL, coords = NULL,
x.col = NULL, y.col = NULL,
pr.col = NULL, plot.col = NULL,
crs = NULL, coord.units = "m",
geometry.source = c("auto",
"snfi", "external",
"none"), validate = TRUE,
coord.nm = NULL,
coord.factor = NULL,
huso.method = c("auto",
"candidate",
"province", "none"),
target.crs = NULL,
boundary = TRUE,
boundary.source = c("auto",
"gisco", "gadm",
"user", "none"),
boundary.object = NULL,
boundary.level = 2,
boundary.path = tools::R_user_dir("basifoR",
"cache"), boundary.ext = "json",
boundary.version = "4.1",
boundary.crs = NULL,
infer.huso = NULL,
na.action = c("keep",
"drop", "error"))
nfi |
Input accepted by |
cub.met |
Same as |
parametro |
Same as |
keep.var |
Same as |
keep.legacy |
Same as |
method_registry |
Same as
|
track_provenance |
Same as |
... |
Additional arguments passed to |
spatial |
Spatial output
mode. |
var |
Forwarded to
|
levels |
Forwarded to |
design |
Forwarded to |
domheight_method |
Dominant-height method forwarded to
|
domheight_registry |
Named
dominant-height registry created with
|
geometry.dt.nm |
Optional table name used to build the geometry
registry. When |
schema |
Optional external |
coords |
Optional coordinate table forwarded to
|
x.col |
Optional X/easting/longitude coordinate column for external coordinate tables. |
y.col |
Optional Y/northing/latitude coordinate column for external coordinate tables. |
pr.col |
Optional province, region, or stratum column used in
|
plot.col |
Optional plot identifier column used in |
crs |
Optional CRS for external coordinates, for example an
EPSG code such as |
coord.units |
Coordinate units recorded in the |
geometry.source |
Forwarded
to |
validate |
Warn about missing |
coord.nm |
Optional SNFI coordinate table name forwarded to
|
coord.factor |
Optional coordinate multiplier for SNFI coordinate tables. By default IFN2 kilometre coordinates are detected and converted to metres. |
huso.method |
UTM-zone
assignment method forwarded to
|
target.crs |
Optional common CRS for SNFI geometries. When
|
boundary |
|
boundary.source |
Boundary
source passed to |
boundary.object |
Optional user-provided |
boundary.level |
GADM administrative level, used when
|
boundary.path |
Cache directory
for optional |
boundary.ext |
GADM extension used by |
boundary.version |
GADM version used by |
boundary.crs |
CRS assigned to |
infer.huso |
Backward-compatible fallback argument forwarded to
|
na.action |
Used only when
|
The default spatial = "attribute" returns a normal
data.frame with metrics2vol metadata intact and
an extra attr(x, "nfi_geometry_registry") sidecar.
This is the safest mode for developing
dendroMetrics_spatial() and inventoryMetrics_spatial()
because no geometry column is passed through the volume
internals. Use spatial = "sf" only when direct spatial
output is needed at this stage.
A metrics2vol object. With
spatial = "attribute", the result remains tabular and carries a
plot-level geometry registry in attr(x, "nfi_geometry_registry")
for later *_spatial() functions. With spatial = "sf",
the function attempts to return an sf object by joining plot
geometries back to the tree-level volume rows. If the volume output no
longer contains a plot identifier, the function warns and returns the
tabular output with the sidecar instead.
Wilson Lara [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
toy <- data.frame(
nfi.nr = 4,
pr = 28,
esta = c("P1", "P2"),
especie = c(21, 21),
Dn = c(180, 260),
altura = c(9.5, 14.2),
x = c(-3.70, -3.69),
y = c(40.40, 40.41)
)
attr(toy, "nfi.nr") <- 4
demo_registry <- snfi_volume_method_registry(list(
VCC = list(
output = "vcc_demo",
fun = function(dbh_mm, h_m, pars) {
pars$k[1] * dbh_mm^2 * h_m
},
raw_unit = "m3 tree-1",
unit = "m3 tree-1",
scale_to_m3 = 1,
build_args = function(ctx, pars, resolved) {
list(dbh_mm = ctx$d_mm, h_m = ctx$h_m, pars = pars)
},
fallback = function(ctx, pars, resolved) NA_real_,
pars = data.frame(
nfi.nr = 4,
pr = 28,
especie = 21,
k = 1e-7
)
)
))
x <- metrics2Vol_spatial(
toy,
parametro = "VCC",
method_registry = demo_registry,
var = c("d", "h", "ba", "n"),
levels = c("esta", "especie"),
spatial = "attribute",
geometry.source = "external",
plot.col = "esta",
x.col = "x",
y.col = "y",
crs = 4326,
boundary = FALSE
)
inherits(x, "metrics2vol")
hasNFIgeometry_spatial(x)
## Spanish NFI: compute tree metrics, volumes, and carry geometry as an
## attribute sidecar.
## x <- metrics2Vol_spatial(28, nfi.nr = 3, dir = tempdir(),
## parametro = c("VCC", "VSC"))
## inherits(x, "metrics2vol")
## hasNFIgeometry_spatial(x)
## attr(x, "units")
## attr(x, "volume_meta")
## attr(x, "dominant_height_meta")
## Direct sf output for visual checks.
## xsf <- metrics2Vol_spatial(28, nfi.nr = 3, dir = tempdir(),
## parametro = c("VCC", "VSC"),
## spatial = "sf")
## inherits(xsf, "sf")
## Continue from an existing spatial nfiMetrics object.
## nm <- nfiMetrics_spatial(28, nfi.nr = 3, dir = tempdir())
## vv <- metrics2Vol_spatial(nm, parametro = "VCC")
## hasNFIgeometry_spatial(vv)
## Disable spatial behavior and recover the ordinary metrics2Vol workflow.
## y <- metrics2Vol_spatial(28, nfi.nr = 3, dir = tempdir(),
## spatial = "none")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.