# NOT RUN {
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
lidar = readLAS(LASfile, select = "*")
# All the predefined functions
m1 = grid_metrics(lidar, stdmetrics(X,Y,Z,Intensity,ScanAngle,ReturnNumber,Classification,dz=1))
# Convenient shortcut
m2 = grid_metrics(lidar, .stdmetrics)
# Basic metrics from intensities
m3 = grid_metrics(lidar, stdmetrics_i(Intensity))
# All the metrics from intensities
m4 = grid_metrics(lidar, stdmetrics_i(Intensity, Z, Classification, ReturnNumber))
# Convenient shortcut for the previous example
m5 = grid_metrics(lidar, .stdmetrics_i)
# Compute the metrics only on first return
first = lasfilterfirst(lidar)
m6 = grid_metrics(first, .stdmetrics_z)
# Compute the metrics with a threshold at 2 meters
over2 = lasfilter(lidar, Z > 2)
m7 = grid_metrics(over2, .stdmetrics_z)
# Works also with lasmetrics and grid_hexametrics
m8 = lasmetrics(lidar, .stdmetrics)
m9 = grid_hexametrics(lidar, .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)) )
}
m10 = grid_metrics(lidar, myMetrics(Z, Intensity))
# User can write your own convenient shorcuts like this:
.myMetrics = expression(myMetrics(Z,Intensity))
m11 = grid_metrics(lidar, .myMetrics)
# }
Run the code above in your browser using DataLab