0

This code seems to work correctly when I use it with a single las file

f <- function(x) { # user-defined fucntion
  list(mean = mean(x), sd = sd(x))
}

las <- readLAS(<path to las file>)

metrics = pixel_metrics(las, ~f(Z), 30)

metrics

class       : SpatRaster 
dimensions  : 18, 18, 2  (nrow, ncol, nlyr)
resolution  : 30, 30  (x, y)
extent      : 487980, 488520, 6715470, 6716010  (xmin, xmax, ymin, ymax)
coord. ref. :  
source(s)   : memory
names       :     mean,       sd 
min values  :  0.00000,  0.00000 
max values  : 16.49204, 12.88984 

However, with a LAS catalog it looks to be returning an average for all layers

ctg <- readLAScatalog(<path to directory>)

metrics = pixel_metrics(ctg, ~f(Z), 30)

metrics

class       : SpatRaster 
dimensions  : 38, 63, 2  (nrow, ncol, nlyr)
resolution  : 30, 30  (x, y)
extent      : 487140, 489030, 6715350, 6716490  (xmin, xmax, ymin, ymax)
coord. ref. :  
source(s)   : memory
names       :     mean,       sd 
min values  :  0.00000,  0.00000 
max values  : 15.36727, 15.36727

Previously, this worked fine for me, but the behaviour seems to have changed recently.

1 Answer 1

1

This is a bug with terra 1.7.39. Update terra if there is an update or downgrade terra. See also https://github.com/r-lidar/lidR/issues/697. Btw stack exchange is not a place to report bugs.

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