I'm trying to calculate metrics for a LAScatalog with the voxel_metrics function. This is the code I used:

ctg <- readLAScatalog("laspath")
voxel_metrics(ctg, ~mean(Z), 4)

When I run it, I get this message:

Error: Argument is not a LAS object

Can the voxel_metrics function be used with a LAScatalog? (A similar question was asked here, but I don't think the answer applies in this case.)

1 Answer 1


voxel_metrics does not have a version for LAScatalog. The reason is that the output is a data.frame. Unlike spatial objects like sf, SpatRaster or LAS a data.frame can contain anything. It is thus impossible to let the LAScatalog processing engine automatically handle the logic of a function returning a data.frame.

You could convert it into sf with PointZ geometries and record it into geopackage files. This would looks like this

opt_output_files(ctg) = "/path/file/to/export_{ID}"
opt_chunk_buffer(ctg) = 10
ctg@output_options$drivers$sf$extension = ".gpkg"

apply_vm = function(las)
  m = voxel_metrics(las, 8,  ~mean(Intensity))
  m = sf::st_as_sf(m, coords = c("X", "Y", "Z"))

res = catalog_map(ctg, apply_vm)

If your dataset if small enough, you can remove opt_output_files(ctg) to return everything in R as one big sf object.

You are free to find another solution that fits your need. This is just a quick solution I can offer right now.

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.