1

Here is my code :

LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
ctg = readLAScatalog(LASfile)

myMetrics2 <- function(rnu, nor) {
  tab <- table(rnu, nor)
  return(tab)
}

g <- function(chunk) {
  las <- readLAS(chunk)
  if (is.empty(las)) {
    return(NULL)
  }
  metrics <- cloud_metrics(las, myMetrics2(ReturnNumber, NumberOfReturns))
  return(metrics)
}

opt_progress(ctg) <- FALSE
opt_chunk_buffer(ctg) <- 0
opt_chunk_size(ctg) <- 0
opt_output_files(ctg) <- ""

p_metrics <- catalog_apply(ctg, g)

It generate this error :

Error: Duplicated elements found. At least one of the metrics was not a number. Each metric should be a single number.

I don't understand why ?

1 Answer 1

0

Your metrics function return a vectors i.e. several values for a single metric while you are supposed to return a single value per metric.

When you have a single vector to return for the entire point cloud this may be confusing but consider the following case:

myMetrics2 <- function(rnu, nor) {
  tab <- table(rnu, nor)
  avg <- mean(rnu
  return(list(tab, avg))
}

pixel_metrics(las, ~myMetrics2(ReturnNumber, NumberOfReturns))

It is more obvious that this won't work.

As mentioned in the documentation you must return a named list

myMetrics2 <- function(rnu, nor) {
  tab <- table(rnu, nor)
  return(as.list(tab))
}
0

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.