I have a small issue with configuring the lidR package for parametrizing the extracted raster files with grid_metrics() function.

My question is how to set in the catalog options that:

  1. be able to overwrite the results with a second run if I want to run my script several times and I do not want to name each output differently.
  2. instead of .tif I would like to get .grd files as output.

My current code (which is working) is the following:

normalizedctg = catalog(workingdirectory)
opt_output_files(normalizedctg) <- paste(workingdirectory,"/clipped/normalized/{XLEFT}_{YBOTTOM}_height",sep="")
height = grid_metrics(normalizedctg, max(Z),res = resolution)

But with a second run on the same code I get the following error:

Error in .getGDALtransient(x, filename = filename, options = options,  : 
  filename exists; use overwrite=TRUE

1 Answer 1


Your question is related to LAScatalog processing engine tuning. A topic not documented in the official documentation. The only one existing documentation at the time being (june 2019) is a wiki page that provide an example to change the drivers.

In short the drivers used to write objects to files are stored in the LAScatalog object. You can access to them with regular R code. The difficulty is the fact it is not documented.

To save .grd instead of .tif

normalizedctg@output_options$drivers$Raster$extension <- ".grd"
normalizedctg@output_options$drivers$Raster$param$format <- "raster"

To force the overwrite option in raster::writeRaster

normalizedctg@output_options$drivers$Raster$param$overwrite <- TRUE

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.