3

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?

asked Feb 17, 2018 at 4:24

1 Answer 1

3

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)))
Aaron
52k30 gold badges161 silver badges327 bronze badges
answered Feb 17, 2018 at 5:47
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.