0

Would it 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 1 meters cell. I'm trying to compute using the function of the package stdmetrics_z(z) but I had an error with fast_table

myMetrics2 = function (z) { 
  n = length(z)
  zmax = max(z)
  zmean = mean(z)
  if (zmax <= 0) {
    d = rep(0, 9)
  }
  else {
    breaks = seq(0.2, 25, 2.8)
    d = findInterval(z, breaks)
    d = fast_table(d, 10)
    d = d/sum(d) * 100
    d = cumsum(d)[1:9]
    d = as.list(d)
  }
  names(d) = paste0("zpcum", 1:9)
  metrics = c( d)
  return(metrics)
}

metric2=grid_metrics(ctgn.i, ~myMetrics2(z, res=1)
#> Processing [=========================================] 100% (1/1) eta:  0s
#> Error: could not find function "fast_table"
1
  • fast_table is an internal function of the lidR package. You took the source code of the package and put it in the your global environment. You cannot expect this to work.
    – JRR
    Commented Feb 6, 2020 at 14:38

1 Answer 1

2

I guess you are trying to write a function like this. But it is hard to say because your code example is not related at all to your text description. I based this answer on your text description.

f = function(z) {
  n02.3 = sum(z >= 0.2 & z <= 3)
  n = length(z)
  return(list(ratio = n02.3/n))
}

metric2 = grid_metrics(ctgn.i, ~f(z), res = 1)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.