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
612 stars 133 forks source link

polygon metrics does not work with LAScatalog #773

Closed GregorDall closed 3 months ago

GregorDall commented 3 months ago

Hi,

I am just adapting my workflow from using single LAS files to the LAScatalog processing workflow. Is it possible to use a LAScatalog with polygon_metrics or do I have to use catalog_apply?

temp <- polygon_metrics(las = mylas, func = ~list( minZ = min(Z), maxZ = max(Z), nZ = length(Z)), geometry = mygeometry)

Error in UseMethod("polygon_metrics", las): non-applicable method for 'polygon_metrics' applied to an object of class "LAScatalog"

Best Gregor

Jean-Romain commented 3 months ago

This is correct there is no polygon_metrics for LAScatalog. The reason is that it is impossible to handle such algorithm in the general case with the LAScatalog processing engine.

Assume you have a large and long polygon polygon that encompasses 3 tiles. This is impossible to handle with an processing engine that processes sequentially square regions.

If you are sure your polygons are relatively small and can fit in a chunk + its buffer, then, below are the steps of a custom function in catalog_apply:

  1. Get the bbox of the chunk
  2. Keep only polygons with the centroid inside the bbox
  3. Compute polygon_metrics with these polygons

Process with a relatively large buffer to ensure that the polygons with a centroid inside the chunk are not beyond the chunk + buffer.