Learn R Programming

lidR (version 2.0.2)

tree_metrics: Compute metrics for each tree

Description

Once the trees are segmented, i.e. attributes exist in the point cloud that reference each tree, computes a set of user-defined descriptive statistics for each individual tree. This is the "tree version" of grid_metrics.

Usage

tree_metrics(las, func, field = "treeID")

Arguments

las

An object of class LAS or LAScatalog.

func

The function to be applied to each tree.

field

character. The column name of the field containing tree IDs. Default is "treeID"

Value

A SpatialPoinsDataFrame that references the xy-position with a table of attributes that associates the z-elevation (highest points) of the trees and the id of the trees, plus the metrics defined by the user.

Working with a <code>LAScatalog</code>

This section appears in each function that supports a LAScatalog as input.

In lidR when the input of a function is a LAScatalog the function uses the LAScatalog processing engine. The user can modify the engine options using the available options. A careful reading of the engine documentation is recommended before processing LAScatalogs. Each lidR function should come with a section that documents the supported engine options.

The LAScatalog engine supports .lax files that significantly improve the computation speed of spatial queries using a spatial index. Users should really take advantage a .lax files, but this is not mandatory.

Supported processing options

Supported processing options for a LAScatalog (in bold). For more details see the LAScatalog engine documentation:

  • chunk size: How much data is loaded at once.

  • chunk buffer*: Mandatory to get a continuous output without edge effects. The buffer is always removed once processed and will never be returned either in R or in files.

  • chunk alignment: Align the processed chunks.

  • cores: How many cores are used.

  • progress: Displays a progression estimation.

  • output_files: Supported templates are {XLEFT}, {XRIGHT}, {YBOTTOM}, {YTOP}, {XCENTER}, {YCENTER} {ID} and, if chunk size is equal to 0 (processing by file), {ORIGINALFILENAME}.

  • laz_compression: write las or laz files

  • select: The function will write files equivalent to the original ones. Thus select = "*" and cannot be changed.

  • filter: Read only points of interest.

Details

By default the function computes the xyz-coordinates of the highest point of each tree and uses xy as tree coordinates in SpatialPoinsDataFrame. z is stored in the table of attributes along with the id of each tree. All the other attributes are user-defined attributes: The following existing functions contain a small set of pre-defined metrics:

Users must write their own functions to create their own metrics. tree_metrics will dispatch the LiDAR data for each segmented tree in the user-defined function. Functions are defined without the need to consider each segmented tree i.e. only the point cloud (see examples).

Examples

Run this code
# NOT RUN {
LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las = readLAS(LASfile, filter = "-drop_z_below 0")

# Mean height and mean intensity for each tree
metrics = tree_metrics(las, list(`Mean Z` = mean(Z), `Mean I` = mean(Intensity)))

# Define your own new metrics function
myMetrics = function(z, i)
{
  metrics = list(
     imean = mean(i),
     imax  = max(i),
     npoint = length(z)
   )

   return(metrics)
}

metrics = tree_metrics(las, myMetrics(Z, Intensity))

# predefined metrics (see ?stdmetrics)
metrics = tree_metrics(las, .stdtreemetrics)
# }

Run the code above in your browser using DataLab