Package 'basifoR'

Title: Retrieval and Processing of the Spanish National Forest Inventory
Description: Data sets of the Spanish National Forest Inventory <https://www.miteco.gob.es/es/biodiversidad/servicios/banco-datos-naturaleza/informacion-disponible/> are processed to compute tree metrics and statistics. Function metrics2Vol() controls most of the routines.
Authors: Wilson Lara <[email protected]>, Cristobal Ordonez <[email protected]>, Felipe Bravo <[email protected]>
Maintainer: Wilson Lara <[email protected]>
License: GPL-3
Version: 0.4
Built: 2024-10-31 03:34:55 UTC
Source: https://github.com/cran/basifoR

Help Index


DBH metrics

Description

This function can format tree diameters at breast height and tree heights according to the sampling design of the Spanish National Forest Inventory (SNFI). The function is used by other routines of basifoR to derive tree metrics, see Details section. Implementation of this function using data sets of the SNFI can be burdensome. Use dendroMetrics instead to recursively derive tree metrics.

Usage

dbhMetric(dbh, met = "d")

Arguments

dbh

numeric. Either diameters at breast height (mm) or tree heights (m). Vectors are averaged. Zero values are formatted to NA.

met

character. Any of five metrics: mean diameter at breast height ('d'), basal area ('ba'), number of trees ('n'), or tree height ('h'). Default 'd'.

Details

Replicates of tree diameter 'd' are averaged. The tree heights 'h' are formatted from mm to dm for further evaluation of volume equations. The basal areas are computed transforming the diameters from mm to cm and using the formula: ba (m2 tree-1 ha-1) = pi * d(cm)^2 * (4 * 1E4)^-1. The number of trees per hectare 'n' are calculated considering the sample design of the NFI: each plot consists of four concentric subplots with radii 5, 10, 15, and 25 m. The minimum diameters recorded in the subplots are 7.5, 12.5, 22.5, and 42.5 cm respectively. Considering these, any of four estimates is printed: 127.32, 31.83, 14.15, or 5.09.

Value

numeric. A tree metric: mean diameter (mm), tree basal area (m2 tree-1), number of trees (dimensionless), or tree height (dm).

Author(s)

Wilson Lara <[email protected]>, Cristobal Ordonez <[email protected]>, Felipe Bravo <[email protected]>

Examples

dbh <- dbhMetric(c(10.7, 11.5), 'h')# average tree height (dm)

Summarize dendrometrics

Description

This function can summarize dendrometric data of the Spanish National Forest Inventory (SNFI). It can also control most other functions of the package. Dendrometric variables in the outputs are transformed into stand units, see the Details section.

Usage

dendroMetrics(nfi, summ.vr = "Estadillo", 
    cut.dt = "d == d", 
    report = FALSE, ...)

Arguments

nfi

character or data.frame. URL/path to a compressed SNFI file (.zip) having data of either .dbf or .mdb file extensions; or data frame such as that produced by nfiMetrics; or data frame such as that produced by readNFI.

summ.vr

character or NULL. Name of a Categorical variables in the SNFI data used to summarize the outputs. If NULL then output from metrics2Vol is returned. Default 'Estadillo' processes sample plots.

cut.dt

character. Logical condition used to subset the output. Default 'd == d' avoids subsetting.

report

logical. Print a report of the output in the current working directory.

...

Additional arguments in metrics2Vol or nfiMetrics or readNFI.

Details

Dendrometric variables are summarized according to the levels of the argument summ.vr. The summary outputs include the categorical columns formulated in summ.vr and the variables defined using arguments/defaults in nfiMetrics. These variables include the tree basal area ba ('m2 ha-1'), the average diameter at breast height d ('cm'), the quadratic mean diameter dg ('cm'), the average tree height h ('m'), the number of trees by hectare n ('dimensionless'), and the over bark volume v ('m3 ha-1'). Subsets of the output summary are extracted using logical expressions in argument 'cut.dt', see syntax in Logic.

Value

data.frame. Depending on summ.vr = NULL, an output from metrics2Vol, or a summary of the variables, see Details section.

Author(s)

Wilson Lara <[email protected]>, Cristobal Ordonez <[email protected]>, Felipe Bravo <[email protected]>

Examples

## SNFI Data from the province of Madrid
madridNFI <- system.file("ifn3p28_tcm30-293962.zip", package="basifoR")
rmad <- readNFI(madridNFI)[1:100,]
mmad <- nfiMetrics(rmad)
vmad <- metrics2Vol(mmad)
dmad <- dendroMetrics(vmad, cut.dt = 'h > 8')
head(dmad)
## see metric units
attr(dmad,'units')

## Retrieval of SNFI data in 'www.miteco.gob.es' and computation
## of the corresponding dendrometric summary:


path <- '/es/biodiversidad/servicios/banco-datos-naturaleza/090471228013cbbd_tcm30-278511.zip'
url2 <- httr::modify_url("https://www.miteco.gob.es", path = path)
dmad <- dendroMetrics(url2, cut.dt = 'h >= 11')
head(dmad)
attr(dmad, 'units')

Tree volumes in NFI data

Description

This function computes over bark volumes ('m3') processing tree metrics from databases of the SNFI data and using volume equations established in 2nd NFI, see Details section. To derive dendrometric summaries use dendroMetrics.

Usage

metrics2Vol(nfi, cub.met = "freq", 
    keep.var = FALSE, 
    ...)

Arguments

nfi

character or data.frame. URL/path to a compressed file of the NFI (.zip) having data of either .dbf or .mdb file extensions; or data frame such as that produced by nfiMetrics; or data frame such as that produced by readNFI.

cub.met

character. Cubication method. Default 'freq' implements the equation form that most frequently match the data, see details section. Additional methods have not yet been implemented.

keep.var

logical. Keep the variables used to compute the volumes. Default FALSE.

...

Depending on 'nfi', additional arguments in metrics2Vol or nfiMetrics or readNFI.

Details

The quations from the second SNFI used have the forms 'v ~ par1 + par2 * (d^2) * h', and 'v ~ par1 * (d^par2) * (h^par3)'. These equations estimate over bark volumes in 'dcm3' but the function transform the units so the output volumes have 'm3' units. The function assign equation forms and parameters depending on several variables, including the provincial unit, the tree species, the tree diameter, and the tree height. Consequently, objects from nfiMetrics must have these variables.

Value

data.frame. Depending on keep.var, short or expanded data set. Short data sets contain the volumes v ('m3') plus the metrics defined in nfiMetrics. The expanded data contains additional columns with the variables used to compute the volumes.

Author(s)

Wilson Lara <[email protected]>, Cristobal Ordonez <[email protected]>, Felipe Bravo <[email protected]>

Examples

madridNFI <- system.file("ifn3p28_tcm30-293962.zip", package="basifoR")
rmad <- readNFI(madridNFI)[1:10,]
vmad <- metrics2Vol(rmad)
head(vmad)
## see metric units
attr(vmad,'units')

Tree metrics from NFI data

Description

This function recursively implements dbhMetric on data bases of the Spanish National Forest Inventory (NFI) to derive a variety of tree metrics. Use metrics2Vol to recursively derive the metrics plus over bark volumes.

Usage

nfiMetrics(nfi, var = c("d", 
    "h", "ba", "n", "Hd"), 
    levels = c("esta", 
        "espe"), ...)

Arguments

nfi

character or data.frame. URL/path to a compressed file of the NFI (.zip) having data of either .dbf or .mdb file extensions, or a data frame such as that produced by readNFI.

var

character. Metrics. These can be five: (1) the mean diameter 'd'; (2) the tree height 'h'; (3) the basal area 'ba'; code(4) the number of trees per hectare 'n'; and (5) the dominant height 'Hd', see Details section in dbhMetric for better understanding of the metrics units. Default c('pr','d','h','ba','n','Hd').

levels

character. levels at which the metrics are computed. Pattern matching is supported. Cases are ignored. Default c('esta','espe') matches both the sample plot 'Estadillos' and tree species 'Especie'.,

...

Additional arguments in readNFI.

Value

data.frame containing columns which match the strings in levels, plus the variables defined in var, including the province pr (dimensionless), the diameter d ('mm'), the tree height h ('dm'), the basal area ba ('m2 tree-1'), the number of trees by hectare n (dimensionless), and the tree dominant height Hd ('m').

Author(s)

Wilson Lara <[email protected]>, Cristobal Ordonez <[email protected]>, Felipe Bravo <[email protected]>

Examples

## seconf NFI
madridNFI <- system.file("ifn3p28_tcm30-293962.zip", package="basifoR")
rmad <- readNFI(madridNFI)[1:10,]
mmad <- nfiMetrics(rmad)
head(rmad,3)
## see metric units
attr(rmad,'units')

Read NFI data

Description

This function can retrieve data sets of the Spanish National Forest Inventory (SNFI). It can process either URLs to data stored in the SNFI web page ("http://www.miteco.gob.es") or paths to files locally stored.

Usage

readNFI(nfi, dt.nm = "PCMayores", 
    ...)

Arguments

nfi

character or data.frame. URL/path to a compressed file of the SNFI (.zip) having data of either .dbf or .mdb file extensions.

dt.nm

character. Name of a data set stored in the imported NFI data. Default reads 'PCMayores' (3rd NFI) or 'PIESMA' (2nd NFI).

...

Additional arguments in urlToTemp.

Details

Compressed data having file extensions other than .dbf or .mdb are not supported. Most data bases in 2nd and 3rd stages of the SNFI can be imported directly from http://www.miteco.gob.es using appropriate URLs. Data sets from 2nd SNFI are imported using read.dbf. Data from latter stages are imported using either RODBC (Windows) or mdb.get (unix-alike systems). Data from 4th SNFI must be read from local paths. On Windows, a driver for Office 2010 can be installed via the installer 'AccessDatabaseEngine.exe' available from Microsoft, and the package must be implemented using a 32-bit R version. In the case of unix-alike systems, the linux dependence mdbtools must be installed.

Value

data.frame. A data base of the NFI.

Author(s)

Wilson Lara <[email protected]>, Cristobal Ordonez <[email protected]>, Felipe Bravo <[email protected]>

Examples

madridNFI <- system.file("ifn3p28_tcm30-293962.zip", package="basifoR")
rmad <- readNFI(madridNFI)[1:100,]
head(rmad)

## Retrieval of a data base from the second stage of the second SNFI:


path <- '/es/biodiversidad/servicios/banco-datos-naturaleza/090471228013cbbd_tcm30-278511.zip'
url2 <- httr::modify_url("https://www.miteco.gob.es", path = path)
rnfi <- readNFI(url2)
head(rnfi,3)

Temporary NFI data

Description

This function is implemented by other routines of the package to decompress .zip files with data sets of the SNFI.

Usage

urlToTemp(url., timeOut = timeout(60))

Arguments

url.

character. URL/path to a compressed file of the SNFI (.zip) having data of either .dbf or .mdb file extensions..

timeOut

request. Maximum request time, see timeout. Default timeout(60)

Details

The data sets are decompressed in a temporary file of the local machine. Compressed data containing file extensions other than .mdb or .dbf are not supported.

Value

character. Path to the NFI data (.mdb or .dbf) stored in a temporary file

Author(s)

Wilson Lara <[email protected]>, Cristobal Ordonez <[email protected]>, Felipe Bravo <[email protected]>

Examples

madridNFI <- system.file("ifn3p28_tcm30-293962.zip", package="basifoR")
tfmad <- urlToTemp(madridNFI)
tfmad

## Internet resources fail gracefully with an informative message if
## the resource is not available or has changed (and not give a check
## warning nor error):

path <- '/es/biodiversidad/servicios/banco-datos-naturaleza/090471228013cbbd_tcm30-278511.zip'
url2 <- httr::modify_url("https://www.miteco.gob.es", path = path)

tfmad <- urlToTemp(url2, timeOut=timeout(1))