I am attempting to feed the lidR
gridmetrics function a list of metrics. I can generate the list of metrics within a function (following this example):
myMetrics = function(z, i)
{
metrics = list(
zmean = mean(z),
imean = mean(i),
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)
}
And then feed the list into the gridmetrics
function:
metrics = grid_metrics(lidar, myMetrics(Z, Intensity), 20)
However, I cannot find a way to incorporate individual stdmetrics into the above myMetrics
function.
How, for example, would I add the zqx
or zkurt
metrics (from this source) into the myMetrics
function, which can then be fed into the gridmetrics
function?
1 Answer 1
You can use the function stdmetrics
inside your custom function like in the following example (using stdmetrics_z
)
myMetrics = function(z, i)
{
lidrmetrics = stdmetrics_z(z)
mymetrics = 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(mymetrics, lidrmetrics))
}
metrics = grid_metrics(lidar, myMetrics(Z, Intensity))
Of course if the function requires more inputs you must update the parameters of your custom function. This is documented in the examples of help("stdmetrics")
.
Also the following works too.
metrics = grid_metrics(lidar, c(myMetrics(Z, Intensity), stdmetrics_z(Z)))
Explore related questions
See similar questions with these tags.