| nfiMetrics_spatial | R Documentation |
Compute tree-level Spanish NFI metrics while preserving plot geometry
This function mirrors the public arguments and calculations of
nfiMetrics but adds an optional spatial sidecar. The metric
computation itself is delegated to the original nfiMetrics(), so the
returned diameter, height, basal-area, trees-per-hectare, dominant-height,
dominant-diameter, unit, and design metadata remain consistent with the
non-spatial workflow.
Spatial information is prepared before the metric call by invoking
readNFI_spatial() with spatial = "attribute" and copied back to the
metric output after nfiMetrics() finishes. Thus the geometry column
never travels through the tree-metric calculations. If spatial =
"sf", the function reconstructs an sf point object only at the end.
nfiMetrics_spatial(nfi,
var = c("d", "h",
"ba", "n", "Hd",
"Dd"), levels = c("esta",
"espe"), design = snfi_design(),
domheight_method = "Hd",
domheight_registry = dominant_height_method_registry(),
..., spatial = c("attribute",
"sf", "none",
"inherit"), 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 |
|
var |
Same as |
levels |
Same as |
design |
Same as |
domheight_method |
Dominant-height method code resolved
through |
domheight_registry |
Named
dominant-height registry created with
|
... |
Additional arguments passed to |
spatial |
Spatial output
mode. |
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 the nfiMetrics metadata intact
and an extra attr(x, "nfi_geometry_registry") sidecar.
This is the safest mode for developing
metrics2Vol_spatial() and dendroMetrics_spatial()
because no geometry column is passed through the metric
internals. Use spatial = "sf" only when direct spatial
output is needed at this stage.
A nfiMetrics 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 metric rows. If the metric 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", "P1", "P2"),
espe = c(21, 21, 25),
Dn = c(120, 185, 260),
altura = c(7.1, 9.4, 13.2),
x = c(-3.70, -3.70, -3.69),
y = c(40.40, 40.40, 40.41)
)
attr(toy, "nfi.nr") <- 4
x <- nfiMetrics_spatial(
toy,
var = c("d", "h", "ba", "n"),
levels = c("esta", "espe"),
spatial = "attribute",
geometry.source = "external",
plot.col = "esta",
x.col = "x",
y.col = "y",
crs = 4326,
boundary = FALSE
)
inherits(x, "nfiMetrics")
hasNFIgeometry_spatial(x)
## Spanish NFI: compute metrics and carry geometry as an attribute sidecar.
## x <- nfiMetrics_spatial(28, nfi.nr = 3, dir = tempdir())
## inherits(x, "nfiMetrics")
## hasNFIgeometry_spatial(x)
## reg <- getNFIgeometry_spatial(x)
## reg$geometry
## attr(x, "dominant_height_meta")
## Direct sf output for visual checks.
## xsf <- nfiMetrics_spatial(28, nfi.nr = 3, dir = tempdir(),
## spatial = "sf")
## inherits(xsf, "sf")
## Disable spatial behavior and recover the ordinary nfiMetrics workflow.
## y <- nfiMetrics_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.