rcataloglidarlaslidr

How to configure lidR catalog to save files with file name


I'm trying to learn how to use the options of catalog() within the lidR package in R. I'd like to save directly the processed files, for example, using grid_terrain() function over a catalog and save files keeping the filename of the original LAZ/LAS file.

As you can see in the guide of the package, catalog has the option of save the file using things like {XBOTTOM}_{ID}:

# Internal engine will not return results into R. Instead it will write results in files.
opt_output_files(ctg) <- "/path/to/folder/templated_filename_{XBOTTOM}_{ID}

I'd like to save the files using the same filename, but, I don't know how to configure that part with {} in the opt_output_files() option. I tried several things like, for instance: opt_output_files(cat) <- paste0(output,"/{data$filename}") but, it doesn't work.

lasdir <- "C:/lazfiles"
output <- "C:/output"

cat <- catalog(lasdir)
lasfiles <- cat@data$filename #with this you can see the filenames
opt_progress(cat) <- TRUE
opt_output_files(cat) <- paste0(output,"/{data$filename}")
opt_cores(cat) <- 3
opt_chunk_buffer(cat) <- 20

#function that I want to use over the catalog files
mdt <- grid_terrain(cat, res = 5, algorithm = "knnidw"(k = 5, p = 2)) 

Solution

  • Found the answer in the grid_terrain help section "supported processing options":

    output_files: Return the output in R or write each cluster’s output in a file. Supported templates are ... , ORIGINALFILENAME.

    This is the solution:

    opt_output_files(cat) <- paste0(output,"/{ORIGINALFILENAME}")