This question can be considered an extension of Create a DTM using the TIN algorithm
I am providing multiple LAS files as a catalog list to the rasterize_terrain
which breaks the LAS into smaller chunks and returns DTM .tif rasters for each chunk.
The I have to use the terra
package to merge these smaller DTM rasters into one big raster. Now is there a way to directly get a single DTM raster using just the lidR
package? Or is there a better way to do this or is my current code the correct approach?
I did try merging (catalog_retile() function
) all input LAS files into a single LAS to get a single DTM raster, however rasterize_terrain failed with an interpolation error. So, I guess it is best to use multiple LAS files.
Current code:
library(lidR)
library(terra)
# Create a LAS catalog
LAS_List = readLAScatalog("path", recursive = TRUE)
# Create an output destination to store the DTM raster files
opt_output_files(LAS_list) <- paste0("folder/{*}_dtm")
# Create a DTM using the TIN method
dtm_tin = rasterize_terrain(LAS_List, res = 1, algorithm = tin())
# Create a list of rasters and store their path
FL_DTMs_List = list.files(getwd(), "tif$", full.names=TRUE) # the $ exludes aux-files
# Create a SpatRasterCollection using the terra package
DTM_ic = sprc(lapply(FL_DTMs_List, rast))
# Merge these DTMs into a single raster
terra::merge(DTM_ic, filename = "path/DTM/DTM.tif")