r-lidar / lidR

Airborne LiDAR data manipulation and visualisation for forestry application
https://CRAN.R-project.org/package=lidR
GNU General Public License v3.0
587 stars 132 forks source link

plot_metrics fails with a single plot #664

Closed Jean-Romain closed 1 year ago

Jean-Romain commented 1 year ago
library(sf)
library(lidR)
ctg <- readLAScatalog(system.file("extdata", "example.laz", package = "rlas"))
plt <- data.frame(place = "plot_1", x = 339008, y = 5248001)
plt <- st_as_sf(x = plt, coords = c("x", "y"), crs = st_crs(ctg))
r <- 11.35

myMetrics = function(z, i)
{
  res = 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(res)
}

res <- plot_metrics(ctg,func = ~myMetrics(Z, Intensity), plt, radius = r)
#> Error in as.list.default(X) : no method for coercing this S4 class to a vector

It works with two plots

plt = rbind(plt, plt)