# NOT RUN {
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las <- readLAS(LASfile, select = "*", filter = "-keep_random_fraction 0.5")
# All the predefined metrics
m1 <- grid_metrics(las, ~stdmetrics(X,Y,Z,Intensity,ReturnNumber,Classification,dz=1), res = 40)
# Convenient shortcut
m2 <- grid_metrics(las, .stdmetrics, res = 40)
# Basic metrics from intensities
m3 <- grid_metrics(las, ~stdmetrics_i(Intensity), res = 40)
# All the metrics from intensities
m4 <- grid_metrics(las, ~stdmetrics_i(Intensity, Z, Classification, ReturnNumber), res = 40)
# Convenient shortcut for the previous example
m5 <- grid_metrics(las, .stdmetrics_i, res = 40)
# Works also with cloud_metrics and hexbin_metrics
m6 <- cloud_metrics(las, .stdmetrics)
m7 <- hexbin_metrics(las, .stdmetrics)
# Combine some predefined function with your own new metrics
# Here convenient shortcuts are no longer usable.
myMetrics = function(z, i, rn)
{
first <- rn == 1L
zfirst <- z[first]
nfirst <- length(zfirst)
above2 <- sum(z > 2)
x <- above2/nfirst*100
# User's metrics
metrics <- list(
above2aboven1st = x, # Num of returns above 2 divided by num of 1st returns
zimean = mean(z*i), # Mean products of z by intensity
zsqmean = sqrt(mean(z^2)) # Quadratic mean of z
)
# Combined with standard metrics
return( c(metrics, stdmetrics_z(z)) )
}
m10 <- grid_metrics(las, ~myMetrics(Z, Intensity, ReturnNumber), res = 40)
# Users can write their own convenient shorcuts like this:
.myMetrics = ~myMetrics(Z, Intensity, ReturnNumber)
m11 <- grid_metrics(las, .myMetrics, res = 40)
# }
Run the code above in your browser using DataLab