Learn R Programming

lidR (version 1.6.1)

grid_hexametrics: Compute metrics for hexagonal cells

Description

Computes a series of descriptive statistics for a LiDAR dataset within hexagonal cells from a hexagonal grid pattern. This function is identical to grid_metrics or grid_metrics3d or tree_metrics but with hexagonal cells instead of classical square pixels. Please refer to grid_metrics for more information.

Usage

grid_hexametrics(.las, func, res = 20, splitlines = FALSE, debug = FALSE)

Arguments

.las

An object of class LAS

func

the function to be applied to each hexagonal cell

res

numeric. The inscribed circle radius of a hexagon. Default = 20.

splitlines

logical. If TRUE the algorithm will compute the metrics for each flightline individually. It returns the same cells several times in overlaps.

debug

logical. If you encounter a non trivial error try debug = TRUE.

Value

It returns a data.table containing the metrics for each hexagonal cell. The table has the class "lashexametrics" enabling easy plotting.

Examples

Run this code
# NOT RUN {
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
lidar = readLAS(LASfile)

# Maximum elevation with a resolution of 4 m
hm = grid_hexametrics(lidar, max(Z), 4)
plot(hm)

# Mean height with a resolution of 20 m
hm = grid_hexametrics(lidar, mean(Z))
plot(hm)

# Define your own new metrics
myMetrics = function(z, i)
{
  metrics = list(
     zwimean = sum(z*i)/sum(i), # Mean elevation weighted by intensities
     zimean  = mean(z*i),       # Mean products of z by intensity
     zsqmean = sqrt(mean(z^2))  # Quadratic mean
   )

   return(metrics)
}

metrics = grid_hexametrics(lidar, myMetrics(Z, Intensity), 10)

plot(metrics, "zwimean")
plot(metrics, "zimean")
plot(metrics, "zsqmean")
#etc.
# }

Run the code above in your browser using DataLab