| readNFIsf | R Documentation |
readNFIsf: read a Spanish NFI table as an sf point data frame.
Read one Spanish National Forest Inventory table and return an
sf object with plot geometries. The table requested by
dt.nm becomes the attribute table. Coordinates come from the
appropriate plot-coordinate table detected from listNFI_tables().
readNFIsf(nfi, nfi.nr = 4,
dt.nm = "PCMayores",
coord.nm = NULL,
file_ext = NULL,
file_name = NULL,
validate = TRUE,
..., crs = NULL,
keep.coord.meta = FALSE,
mixed.crs = c("na",
"error"), na.action = c("keep",
"drop", "error"),
infer.huso = NULL)
nfi |
Input accepted by |
nfi.nr |
|
dt.nm |
Table to import and preserve as the sf attribute table. |
coord.nm |
Optional coordinate table name. If |
file_ext |
Optional file extension passed to
|
file_name |
Optional file name filter for the main-table read. Coordinate discovery ignores this argument. |
validate |
|
... |
Additional arguments passed to |
crs |
Optional CRS passed to |
keep.coord.meta |
Keep Huso/datum/EPSG metadata columns in
the sf attribute table. Otherwise they are
stored in |
mixed.crs |
What to do when rows imply more than one EPSG code. |
na.action |
Handling of rows that do not match a coordinate record. |
infer.huso |
Fill missing UTM zones from province code. By default, TRUE for IFN2 and FALSE for IFN3/IFN4. |
This is the high-level spatial reader. It mirrors the usual
readNFI() workflow for the selected dt.nm table, but
returns an sf point data frame. It should complement rather than
replace readNFI(), because the return type changes and a
coordinate table must be available.
The function calls listNFI_tables() once, reuses the
local files in dir, reads the requested table as attributes,
reads the coordinate table separately, and delegates the geometry
construction to addNFIsf().
By default, infer.huso is TRUE for IFN2 and
FALSE for IFN3/IFN4. This prevents silently assigning uncertain
UTM zones for inventories where a province-level fallback may be less
precise than the original map-sheet reference.
An sf data frame. The imported table named by
dt.nm remains the attribute table; plot coordinates are stored
in the geometry column.
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>)
if (interactive()) {
## Real use with a persistent cache directory. This may download data
## the first time and reuse the local files later.
cache <- tools::R_user_dir("basifoR", "cache")
x <- readNFIsf(45, nfi.nr = 4, dt.nm = "PCMayores", dir = cache)
sf::st_crs(x)
attr(x, "coord_reference")
}
## Visual check against a province boundary, if optional packages exist.
## if (interactive() &&
## requireNamespace("geodata", quietly = TRUE) &&
## requireNamespace("terra", quietly = TRUE)) {
## gadm <- geodata::gadm("ESP", level = 2, path = tempdir())
## gadm_sf <- sf::st_as_sf(gadm)
## plot(sf::st_geometry(gadm_sf))
## plot(sf::st_geometry(sf::st_transform(x, sf::st_crs(gadm_sf))),
## add = TRUE, pch = 16, cex = 0.3)
## }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.