# NOT RUN {
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
lidar = readLAS(LASfile, all = TRUE)
# All the predefined functions
lidar %>% grid_metrics(stdmetrics(X,Y,Z,Intensity, ScanAngle,
ReturnNumber, Classification, pulseID,
dz = 1))
# Convenient shortcut
lidar %>% grid_metrics(.stdmetrics)
# Basic metrics from intensities
lidar %>% grid_metrics(stdmetrics_i(Intensity))
# All the metrics from intensities
lidar %>% grid_metrics(stdmetrics_i(Intensity, Z, Classification, ReturnNumber))
# Convenient shortcut for the previous example
lidar %>% grid_metrics(.stdmetrics_i)
# Compute the metrics only on first return
lidar %>% lasfilterfirst %>% grid_metrics(.stdmetrics_z)
# Compute the metrics with a threshold at 2 meters
lidar %>% lasfilter(Z > 2) %>% grid_metrics(.stdmetrics_z)
# Works also with lasmetrics and grid_hexametrics
lidar %>% lasmetrics(.stdmetrics)
lidar %>% grid_hexametrics(.stdmetrics)
# Combine some predefined function with your own new metrics
# Here convenient shortcuts are no longer usable.
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( c(metrics, stdmetrics_z(z)) )
}
lidar %>% grid_metrics(myMetrics(Z, Intensity))
# You can write your own convenient shorcuts like this:
.myMetrics = expression(myMetrics(Z,Intensity))
lidar %>% grid_metrics(.myMetrics)
# }
Run the code above in your browser using DataLab