I have 96 1 ha (200m by 50 m) plots that I collected TLS data (each file separate). Most of the plots are close to each other and therefore they have overlapping bounding boxes (point clouds don't overlap themselves). I would like to calculate some grid metrics for all 96 plots using lidR package.

ctg <- readLAScatalog("infolder", filter = "-drop_z_above 1.3 -drop_class 2", chunk_size = 0,
                      chunk_buffer = 0)
opt_chunk_size(ctg) <- 0
opt_chunk_buffer(ctg) <- 0
opt_output_files(ctg) <- "outfolder/{ORIGINALFILENAME}"

hmean <- grid_metrics(ctg, mean(Z), 0.1)

Since I am giving chunk size of 0, catalog class considering bounding boxes as tiles and calculating metrics based on the bounding boxes. For this reason, I am getting raster image of a file which also includes part of neighboring image. Also, following warning message from R also referred to this problem.

Be careful, some tiles seem to overlap each other. lidR may return incorrect outputs with edge artifacts when processing this catalog.

enter image description here

enter image description here

If I want to make small chunks, size of 10m, lidR gives warning:

Be careful, a chunk size smaller than 250 is likely to be irrelevant.
Be careful, some tiles seem to overlap each other. lidR may return incorrect outputs with edge artifacts when processing this catalog.

How to calculate grid metrics for each file separately in my case?

1 Answer 1


The default behavior of lidR is to work by chunk or region of interest in such a way that the extent of the collection is covered by the chunks and that the output is a wall-to-wall output. You have perfectly understood the problem. Your files are too close to each other so it loads a portion of the neighbors that overlap the bounding box.

Your idea of using buffer = 0 + chunk = 0 is correct but does not actually works because you want to process strictly independent files. In short you want to loop through files. The problem is that the package is designed to processed non-independent files and to produce a continuous wall-to-wall output.

You can use

opt_independent_file(ctg) <- TRUE

This will set buffer = 0, chunk = 0 and disable wall-to-wall guarantees. This is equivalent to

opt_chunk_size(ctg) <- 0
opt_chunk_buffer(ctg) <- 0
opt_wall_to_wall(ctg) <- FALSE

But yet it won't work because grid_metrics does not respects the buffer (this is mentioned in the doc) and always adds a small buffer to guarantee a strict wall-to-wall output. Your case was not actually planned and must be fixed internally. This will be improved in next release (v3.0.2).

Thus your last option (waiting next release) is to loop manually. No buffer, by file, no wall-to-wall guarantees make the engine being a regular loop actually.

for (file in ctg$filename)
   las = readLAS(file, filter = "-drop_z_above 1.3 -drop_class 2")
   m = grid_metrics(...)
   writeRaster(m, ...)
  • for loop works perfectly. Thank you!
    – Sher
    Commented Jun 23, 2020 at 4:37

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.