1

I am trying to create a DTM on a county wide level (so using LAS catalog). The lidRworkbook advises to use a buffer when using the TIN method, however the workbook doesn't show how to do that. So how can I first create this buffer? And how can I then use this buffer to create a dtm_tin?

On a side note is there a way to directly store the DTM raster to disk rather than first the rasterize_terrain tool first saves the DTM to memory (who knows I might run out of memory) and then save it using the raster or terra package?

Code:

# Create a LAS catalog
LAS_List = readLAScatalog("path", recursive = TRUE)

# Create a DTM using the TIN method
dtm_tin = rasterize_terrain(LAS_List, res = 1, algorithm = tin())

1 Answer 1

1

The way to work with a LAScatalog is explained in chap 14. The buffer is explained in section 14.7.2.

The default is 50 m buffer so your code is already correct.

To store the raster on disk see section 14.8.2. e.g

opt_output_files(LAS_list) <-  paste0("folder/{*}_dtm")

The path must be templated to generate one file per chunk. This is not explicitely mentionned in 14.8.2 but see help("LAScatalog-class")

Output options

The slot ⁠@output_options⁠ contains a list of options that determine how chunks (the sub-areas that are sequentially processed) are written. By "written" we mean written to files or written in R memory.

output_files: string. If output_files = "" outputs are returned in R. Otherwise, if output_files is a string the outputs will be written to files. This is useful if the output is too big to be returned in R. A path to a filename template without a file extension (the engine guesses it for you) is expected. When several files are going to be written a single string is provided with a template that is automatically filled. For example, the following file names are possible:

"/home/user/als/normalized/file_{ID}_segmented" "C:/user/document/als/zone52_{XLEFT}_{YBOTTOM}_confidential" "C:/user/document/als/{ORIGINALFILNAME}_normalized" This option will generate as many filenames as needed with custom names for each file. The allowed templates are {XLEFT}, {XRIGHT}, {YBOTTOM}, {YTOP}, {ID}, {XCENTER}, {YCENTER}, {ORIGNALFILENAME}. See opt_output_files.

8
  • Awesome, but I am still a bit confused, do I need to first run opt_output_files(LAS_list) <- paste0("folder/{*}_dtm") and then run rasterize_terrain which will automatically save the DTM raster to the disk path defined using opt_output_files? Jun 2, 2023 at 19:40
  • So I first ran pt_output_files(LAS_List) = paste0("O:/folder/filename_dtm") and then I ran dtm_tin = rasterize_terrain(BC_LAS_List, res = 1, algorithm = tin()). First thing I noticed was that the memory was still being used up. Also a little later I got this error: error occurred when processing the chunk 2. Try to load this chunk with: chunk <- readRDS("C:\Users\AppData\Local\Temp\RtmpeoYno9/chunk2.rds") las <- readLAS(chunk) [writeRaster] file exists. You can use overwrite=TRUE to overwrite it Jun 2, 2023 at 20:15
  • 1
    Your path is not templated. See my edited anwser
    – JRR
    Jun 2, 2023 at 20:52
  • 1
    There is nothing in {} I'm surprised it does not crash, fails or whatever. Anyway it won't work.
    – JRR
    Jun 5, 2023 at 12:29
  • 1
    {ORIGNALFILENAME}. Or {*} is understood and maybe * is understood as well.
    – JRR
    Jun 5, 2023 at 13:39

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.