Learn R Programming

lidR (version 2.2.5)

hexbin_metrics: Area-Based Approach in hexagonal cells.

Description

Computes a series of descriptive statistics for a LiDAR dataset within hexagonal cells. This function is identical to grid_metrics but with hexagonal cells instead of square pixels. After all, we conduct circular plot inventories and we map models on pixel-based maps. hexbin_metrics provides the opportunity to test something else. Refer to grid_metrics for more information.

Usage

hexbin_metrics(las, func, res = 20)

Arguments

las

An object of class LAS.

func

formula. An expression to be applied to each hexagonal cell.

res

numeric. To be consistent with grid_metrics, the square of res give the area of the hexagonal cells, like in grid_metrics. The difference being the fact that for square pixels this is obvious. Here res = 20 gives 400-square-meter hexagonal cells.

Value

A hexbin object from package hexbin or a list of hexbin objects if several metrics are returned.

See Also

Other metrics: cloud_metrics(), grid_metrics(), point_metrics(), tree_metrics(), voxel_metrics()

Examples

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

col = grDevices::colorRampPalette(c("blue", "cyan2", "yellow", "red"))

# Maximum elevation with a resolution of 8 m
hm = hexbin_metrics(lidar, ~max(Z), 8)
hexbin::plot(hm, colramp = col, main = "Max Z")

# Mean height with a resolution of 20 m
hm = hexbin_metrics(lidar, ~mean(Z), 20)
hexbin::plot(hm, colramp = col, main = "Mean Z")

# 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 = hexbin_metrics(lidar, ~myMetrics(Z, Intensity), 10)

hexbin::plot(metrics$zwimean, colramp = col, main = "zwimean")
hexbin::plot(metrics$zimean, colramp = col, main = "zimean")
hexbin::plot(metrics$zsqmean, colramp = col, main = "zsqmean")
# }

Run the code above in your browser using DataLab