I am porting my existing code to lidR version 2.0 and would like someone to let me know if I am coding efficiently. My objective is:
- to process a directory of LAS files
- normalize las files
- calculate stdmetrics using grid_metrics
- write out results in a data frame that I can use for subsequent analysis
To perform all these step at once I'm trying to use the function catalog_apply
to apply user-defined function. What I did so far is:
Load a LAScatalog
and set some processing options
las.catalogue <- catalog("F://Work//LASTest")
opt_cores(las.catalogue) <- 4L
opt_chunk_size(las.catalogue) <- 260
opt_chunk_buffer(las.catalogue) <- 10
Define my function that is expected to read sequentially some chunks of the point cloud, normalize this point cloud chunk and computed metrics in a area based approach.
stat.function <- function(las)
{
las = lasnormalize(las, tin())
metrics <- grid_metrics(las, .stdmetrics_z, res = 20)
# I think I am supposed to remove buffers but need advice on how to do
return(metrics)
}
Then with catalog_apply
I sequentially run my function on my catalog
metrics <- catalog_apply(las.catalogue, stat.function, .options = opt)
To finish I merge the list of outputs for each chunk into a single RasterBrick
. Because I want a data.frame
I convert the RasterBrick
into a data.frame
metric.merge <- do.call(raster::merge, metrics)
metrics <- raster::as.data.frame(metric.merge,xy=TRUE, na.rm = TRUE)
I'm not yet comfortable with the new design of the lidR
package. Am I on the right track to perform my computation?