Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

voxel_metrics

Voxelize the space and compute metrics for each voxel


Description

This is a 3D version of grid_metrics. It creates a 3D matrix of voxels with a given resolution. It creates a voxel from the cloud of points if there is at least one point in the voxel. For each voxel the function allows computation of one or several derived metrics in the same way as the grid_metrics functions. The function will dispatch the LiDAR data for each voxel in the user's function (see grid_metrics).

Usage

voxel_metrics(las, func, res = 1, ..., all_voxels = FALSE)

Arguments

las

An object of class LAS.

func

formula. An expression to be applied to each voxel (see also grid_metrics).

res

numeric. The resolution of the voxels. res = 1 for a 1x1x1 cubic voxels. Optionally res = c(1,2) for non-cubic voxels (1x1x2 cuboid voxel).

...

Unused

all_voxels

boolean. By default the function returns only voxels that contain 1 or more points. Empty voxels do not exist as the metrics are undefined. If all_voxels = TRUE all the voxels are returned and metrics are NA for voxels with 0 points.

Value

It returns a data.table containing the metrics for each voxel. The table has the class lasmetrics3d enabling easier plotting. It also has an attribute res that stores the resolution.

See Also

Examples

LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las <- readLAS(LASfile)

# Cloud of points is voxelized with a 8-meter resolution and in each voxel
# the number of points is computed.
vm <- voxel_metrics(las, ~length(Z), 8)

# Cloud of points is voxelized with a 8-meter resolution and in each voxel
# the mean intensity of points is computed.
vm <- voxel_metrics(las, ~mean(Intensity), 8)
#plot(vm, color = "V1", colorPalette = heat.colors(50), trim = 60)

# Define your own metric function
myMetrics = function(i)
{
  ret = list(
     npoints = length(i),
     imean   = mean(i)
   )

   return(ret)
}

voxels <- voxel_metrics(las, ~myMetrics(Intensity), 8)

#plot(voxels, color = "imean", colorPalette = heat.colors(50), trim = 60)
#etc.

attr(voxels, "res")

lidR

Airborne LiDAR Data Manipulation and Visualization for Forestry Applications

v3.1.2
GPL-3
Authors
Jean-Romain Roussel [aut, cre, cph], David Auty [aut, ctb] (Reviews the documentation), Florian De Boissieu [ctb] (Fixed bugs and improved catalog features), Andrew Sánchez Meador [ctb] (Implemented wing2015() for segment_snags()), Bourdon Jean-François [ctb] (Contributed to Roussel2020() for track_sensor()), Gatziolis Demetrios [ctb] (Implemented Gatziolis2019() for track_sensor())
Initial release
2021-03-11

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.