I am trying to compute my own metric using LidR. I would like to compute the canopy cover metric as
(# of first returns > 2m) / (total number of first returns)
The package suggested this function from the Examples to compute this metric
myMetrics = function(z,rn){
first = rn == 1L
zfirst = z[first]
nfirst = length(zfirst)
above2 = sum(z> 2)
above2
x =(above2/nfirst)*100
x
# User's metrics
metrics = list(
above2aboven1st = x, # Num of returns above 2 divided by num of 1st returns
zsqmean = sqrt(mean(z^2)) # Quadratic mean of z
)
metrics
# Combined with standard metrics
return( c(stdmetrics_z(z),metrics))
}
metrics = grid_metrics(las, ~myMetrics(Z, rn=ReturnNumber))
However, the results of the metric using this function does not work correctly, since my values range between 0 and 300
it would be possible to calculate a density metric in height intervals as in FUSION or Lastools?
e.g number of all returns between 0.2 and 3 meters/number of total returns in 20 meters cell