| inventoryMetrics_spatial | R Documentation |
Run the complete inventory workflow while preserving optional plot geometry
This function is a conservative spatial companion to
inventoryMetrics. It keeps the original calculation
engines for Spanish NFI and external inventories, but prepares or reuses a
plot-level geometry registry and carries that registry in attributes. The
geometry column is reconstructed only at the end when spatial =
"sf". The original inventoryMetrics() function is not replaced.
inventoryMetrics_spatial(nfi,
backend = c("auto",
"snfi", "external"),
summ.vr = "Estadillo",
cut.dt = "d == d",
report = FALSE, mc.cores = getOption("mc.cores",
1L), design = NULL,
schema = NULL, method_registry = NULL,
domheight_method = "Hd_strict",
domheight_registry = dominant_height_method_registry(),
parameter_table = NULL,
..., spatial = c("attribute",
"sf", "none",
"inherit"), spatial.summary = c("auto",
"centroid", "none"),
keep.geometry.meta = TRUE,
geometry.role.name = NULL,
geometry.dt.nm = NULL,
coord.nm = 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"), file_ext = NULL,
file_name = NULL,
coord.factor = NULL,
huso.method = c("auto",
"candidate",
"xgap", "province",
"none"), huso.candidates = NULL,
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,
validate = TRUE,
na.action = c("keep",
"drop", "error"))
nfi |
Inventory source accepted by the selected |
backend |
Backend selector. The
default infers |
summ.vr |
Grouping variable passed to the selected
|
cut.dt |
Logical expression used by the |
report |
Request |
mc.cores |
Number of cores passed to the
selected |
design |
Optional sampling |
schema |
Optional external |
method_registry |
Optional volume method registry passed to
the selected |
domheight_method |
Dominant-height method passed to
|
domheight_registry |
Named
dominant-height registry created with
|
parameter_table |
Optional parameter table for external inventories. |
... |
Additional arguments forwarded to the selected |
spatial |
Spatial policy.
|
spatial.summary |
Geometry rule after
summarization. |
keep.geometry.meta |
Store geometry role and spatial-summary metadata as attributes. |
geometry.role.name |
Optional visible column containing the
geometry role, for example
|
geometry.dt.nm |
Optional table name used by
|
coord.nm |
Optional coordinate table name for Spanish NFI. |
coords |
Optional external coordinate table. |
x.col |
External X/easting/longitude coordinate column. |
y.col |
External Y/northing/latitude coordinate column. |
pr.col |
Optional province/region key for coordinate joins. |
plot.col |
Optional plot identifier key for coordinate joins. |
crs |
CRS for external coordinates, for example EPSG 25830. |
coord.units |
Coordinate units recorded in the sidecar. |
geometry.source |
Geometry
source passed to |
file_ext |
Optional file extension passed to
|
file_name |
Optional file name filter passed to
|
coord.factor |
Optional coordinate multiplier for Spanish NFI
tables. IFN2 kilometre coordinates are converted
to metres by default in |
huso.method |
UTM-zone
assignment method passed to
|
huso.candidates |
Optional candidate UTM zones passed to
|
target.crs |
Optional common CRS for Spanish NFI geometries. |
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 Huso inference argument passed
to |
validate |
Warn about sidecar or geometry-restoration problems. |
na.action |
Handling of metric rows that
do not match the plot geometry registry when
|
External inventories keep their original backend path. When
external coordinates are supplied through an sf input,
coords, or schema$defaults$spatial, the geometry
registry is carried in attributes and may be restored if the
output keeps compatible grouping keys. Without external
coordinate information, external outputs remain tabular.
When summ.vr is omitted for an external inventory, the
function uses schema$levels when available and otherwise
detects the plot identifier from the prepared input.
External boundaries are never inferred from province-like
columns. Supply an sf polygon or multipolygon through
boundary.object; its CRS must be present or supplied
through boundary.crs.
A result equivalent to the selected backend output, augmented
with class "inventoryMetrics_spatial". With
spatial = "attribute", the output is tabular and carries
the plot geometry in attr(x, "nfi_geometry_registry").
With spatial = "sf", the result is an sf object
when geometry restoration succeeds.
Preserve explicit summ.vr = NULL; NULL selects tree-level output.
Preserve explicit summ.vr = NULL; NULL selects tree-level output.
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>)
ext <- data.frame(
plot = c("P1", "P1", "P2"),
species = c("sp1", "sp1", "sp2"),
diameter_mm = c(120, 185, 260),
height_m = c(7.1, 9.4, 13.2),
x = c(-3.70, -3.70, -3.69),
y = c(40.40, 40.40, 40.41)
)
sch <- new_external_schema(
colmap = list(
plot = "plot",
species = "species",
d = "diameter_mm",
h = "height_m"
),
units = list(d = "mm", h = "m"),
levels = "plot",
keep_cols = c("plot", "species"),
defaults = list(
spatial = list(plot = "plot", x = "x", y = "y", crs = 4326)
)
)
dsg <- new_inventory_design(
sample_area_m2 = 1000,
min_dbh_cm = 7.5,
name = "Square 0.1-ha plot"
)
x <- inventoryMetrics_spatial(
ext,
backend = "external",
schema = sch,
design = dsg,
summ.vr = "plot",
var = c("d", "h", "ba", "n"),
spatial = "attribute",
geometry.source = "external",
boundary = FALSE
)
inherits(x, "inventoryMetrics")
hasNFIgeometry_spatial(x)
## Tabular sidecar output for Spanish NFI:
## x <- inventoryMetrics_spatial(28, nfi.nr = 2, dir = tempdir())
## hasNFIgeometry_spatial(x)
## Direct sf output:
## xsf <- inventoryMetrics_spatial(28, nfi.nr = 2, dir = tempdir(), spatial = "sf")
## inherits(xsf, "sf")
## attr(xsf, "geometry_role")
## Dominant-height calculations use the same inspectable registry exposed
## by nfiMetrics(). Metadata is preserved in attr(x, "dominant_height_meta")
## when Hd is computed.
##
## External inventories keep the original external backend. If the schema
## contains defaults$spatial or the input is sf, the sidecar can be carried.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.