| readNFI_spatial | R Documentation |
Read SNFI data and store plot geometry as an attribute sidecar
This function is a conservative spatial companion to readNFI().
It keeps the ordinary tabular output of readNFI() and stores a
plot-level geometry registry in attr(x, "nfi_geometry_registry").
By default, the returned object remains a data frame and carries geometry
as an attribute sidecar. If spatial = "sf", the function returns an
sf object by joining the sidecar geometry back to each row. The
attribute-sidecar default lets downstream metric functions carry spatial
information without pushing a geometry column through tabular routines.
readNFI_spatial(nfi,
nfi.nr = 4, dt.nm = "PCMayores",
file_ext = NULL,
file_name = NULL,
..., spatial = c("attribute",
"sf", "none"),
geometry.dt.nm = dt.nm,
coord.nm = NULL,
schema = NULL, coords = NULL,
x.col = NULL, y.col = NULL,
pr.col = NULL, plot.col = NULL,
crs = NULL, coord.units = "m",
coord.accuracy.note = NULL,
geometry.source = c("auto",
"snfi", "external",
"none"), validate = TRUE,
coord.factor = NULL,
huso.method = c("auto",
"candidate",
"xgap", "province",
"none"), huso.candidates = NULL,
repair.table.huso = TRUE,
target.crs = NULL,
boundary = FALSE,
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)
nfi |
Inventory source passed to |
nfi.nr |
Spanish NFI stage. Use |
dt.nm |
Main table to read and return as tabular data. |
file_ext |
Optional file extension passed to |
file_name |
Optional file-name filter passed to |
... |
Additional arguments passed to |
spatial |
|
geometry.dt.nm |
Table used to build the geometry registry. In
most SNFI workflows this can match |
coord.nm |
Optional SNFI coordinate table name. If |
schema |
Optional |
coords |
Optional external coordinate table. Use this for non-
Spanish inventories when coordinates live in a separate
table. It can be a data frame or an |
x.col |
Optional X/easting/longitude column for external
coordinate tables. If |
y.col |
Optional Y/northing/latitude column for external
coordinate tables. If |
pr.col |
Optional province, region, or stratum key for external coordinate matching. It is not required for one-region external inventories. |
plot.col |
Optional plot identifier column for external
coordinate matching. If |
crs |
Optional CRS for external coordinates, passed to
|
coord.units |
Coordinate units recorded in the external |
coord.accuracy.note |
Optional note describing the accuracy or provenance of user-supplied coordinates. This is most useful when replacing public inventory coordinates with field-validated plot-centre coordinates. Spanish NFI public coordinates receive an automatic accuracy note. |
geometry.source |
Source used
to build the sidecar. |
validate |
Warn when duplicate plot geometries are found or when geometry cannot be attached. |
coord.factor |
Optional coordinate multiplier for SNFI coordinate tables. By default IFN2 kilometre coordinates are detected and converted to metres. |
huso.method |
Method for
assigning SNFI UTM zones when the coordinate table
does not contain a direct |
huso.candidates |
Optional candidate UTM zones for SNFI Huso inference.
Use, for example, |
repair.table.huso |
|
target.crs |
Optional common CRS for projected SNFI geometries.
When |
boundary |
|
boundary.source |
Boundary
source. |
boundary.object |
Optional user-provided |
boundary.level |
GADM administrative level used when
|
boundary.path |
Cache
directory used for optional |
boundary.ext |
GADM extension used by |
boundary.version |
GADM version used by |
boundary.crs |
CRS assigned to |
infer.huso |
Backward-compatible argument forwarded to the
fallback |
For Spanish NFI sources, the coordinate note is stage-specific
and is stored in
attr(x, "nfi_geometry_registry")$coord_accuracy_note.
IFN2 coordinates are treated as official public locations
derived from the kilometre UTM sampling grid. IFN3 coordinates
are treated as official cartographic plot-location coordinates
in UTM metres; when their Huso is not explicit, CRS
metadata may be reconstructed from candidate Huso fields,
coordinate rules, or fallback methods. IFN4 CoorX/
CoorY are treated as official public coordinates
available before fieldwork for the plot centre. These stage
notes document coordinate interpretation; they do not claim
field-validated exact plot-centre precision.
External inventories or user-supplied coordinate tables do not
receive an automatic coordinate-accuracy note because basifoR
cannot know their measurement protocol or precision. If better
coordinates become available, for example field GPS or
institutional plot-centre coordinates, pass them through
coords, x.col, y.col, plot.col,
and optionally pr.col, with geometry.source =
"external" and provide coord.accuracy.note only when
the coordinate source is known. This replaces the spatial
sidecar while keeping the ordinary readNFI() table and
downstream metric calculations unchanged.
A data frame with the same tabular content returned by
readNFI(). When spatial = "attribute", the object also
carries a plot-level geometry sidecar in
attr(x, "nfi_geometry_registry"). The sidecar stores one geometry
per inventory plot, CRS metadata, coordinate provenance, and normalized
join keys for later *_spatial() metric functions.
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 <- readNFI_spatial(
toy,
spatial = "attribute",
geometry.source = "external",
plot.col = "esta",
x.col = "x",
y.col = "y",
crs = 4326,
boundary = FALSE
)
hasNFIgeometry_spatial(x)
names(getNFIgeometry_spatial(x))
## Keep the ordinary readNFI() output but carry plot geometry in attributes.
## cache <- tools::R_user_dir("basifoR", "cache")
## x <- readNFI_spatial(28, nfi.nr = 3, dt.nm = "PCMayores", dir = cache)
## is.data.frame(x)
## hasNFIgeometry_spatial(x)
## reg <- getNFIgeometry_spatial(x)
## reg$geometry
## Return a true sf object when direct spatial output is wanted.
## xsf <- readNFI_spatial(28, nfi.nr = 3, dt.nm = "PCMayores",
## dir = cache, spatial = "sf")
## inherits(xsf, "sf")
## External inventory: keep tabular data but store geometry sidecar.
## ext <- data.frame(plot_id = 1:2, x = c(440000, 441000),
## y = c(4488000, 4489000), d = c(20, 30))
## y <- readNFI_spatial(ext, spatial = "attribute",
## geometry.source = "external",
## plot.col = "plot_id", x.col = "x", y.col = "y",
## crs = 25830)
## hasNFIgeometry_spatial(y)
##
## External inventory with schema-stored spatial metadata:
## sch <- new_external_schema(
## colmap = list(plot = "plot_id", d = "d"),
## units = list(d = "cm"),
## levels = "plot_id",
## defaults = list(spatial = list(plot = "plot_id", x = "x", y = "y", crs = 25830))
## )
## y2 <- readNFI_spatial(ext, spatial = "attribute", schema = sch)
## hasNFIgeometry_spatial(y2)
##
## Replacing public SNFI coordinates with improved coordinates uses the
## same external sidecar mechanism. The improved table must contain the
## inventory plot keys and coordinate columns.
## improved <- data.frame(pr = 28, Estadillo = c(1, 2),
## x_gps = c(440000, 441000),
## y_gps = c(4488000, 4489000))
## z <- readNFI_spatial(28, nfi.nr = 4, spatial = "attribute",
## geometry.source = "external", coords = improved,
## pr.col = "pr", plot.col = "Estadillo",
## x.col = "x_gps", y.col = "y_gps", crs = 25830,
## coord.accuracy.note = "Field-validated plot-centre coordinates.")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.