0

I have 1300 LAS files and need to generate DTM's with a single TIFF output for each LAS file and I am wondering how I can remove the chunk buffer for the output TIFF files.

I have this code that works to generate the TIFF files but I see that the LiDAR buffer is still present for the TIFF files.

# in/outs
in_las_dir = "D:/lasfiles/"
out_dem_dir = "D:/lasfiles/DTM/"
    
# make a ctg 
ctg = catalog(in_las_dir , filter = "-keep_class 2", espg = 3011)

# options
opt_chunk_buffer(ctg) <- 20 # buffer size
opt_output_files(ctg) <- paste(out_dem_dir,"{ORIGINALFILENAME}",".tif",sep = "") # output fnames
ctg@output_options$drivers$LAS$param$overwrite <- FALSE # dont overwrite new files. 

# generate dtm
dtm <- rasterize_terrain(ctg, res = 1, tin())

The input las files do not overlap

enter image description here

but the output DTM raster seem to overlap along the north/south edge. I measured it and it looks to be 50m and I think I read the default overlap is 50m for chunk buffers.

enter image description here

2 Answers 2

1

There is really nothing special to do. There are indeed some minor mistakes in your code but nothing related to your problem

ctg = readLAScatalog("D:/lasfiles/", recursive = TRUE)
st_crs(ctg) = 3011

opt_output_files(ctg) <- "D:/lasfiles/DTM/*"

dtm <- rasterize_terrain(ctg, res = 1, tin())

There is really nothing else to do.

Edit: according to your edit, I now understand your problem. Your dataset is not properly tiled, and your point cloud shape does not match its bounding box. There is nothing straightforward you can do. lidR is working with bounding boxes. You catalog has overlaps and when you are using readLAScatalog you have a warning. Here you found a side effect of improperly tiled dataset.

5
  • Thanks for the answer! I tried your code as well but I still get overlap for the output rasters. My input las files do not overlap but the output tif files overlap. I assumed it was the buffer causing issues but maybe its another issue. I will try to upload pictures of the output.
    – nola
    Mar 6 at 12:11
  • I see. There is nothing you can do. See my edit.
    – JRR
    Mar 6 at 13:40
  • Thanks for the quick replies! I just remembered that I had to re-project the LAS files which I did for each individual file. I will try to merge them into a massive point cloud, re-project and then re-tile them.
    – nola
    Mar 6 at 13:59
  • You can retile this catalog with lidR. Use catalog_retile. The side effect here is the desired effect
    – JRR
    Mar 6 at 14:01
  • THANK YOU so much!! I was able to do the re-tiling and re-project. will update my question.
    – nola
    Mar 6 at 14:54
0

So here is the solution I came up with. As JRR noted, my LAS tiles were not tiled correctly and this was due to previously re-projecting the single tiles which rotated them slightly and causing issues with the bounding box.

I wasn't able to do the re-tiling/re-projecting with only lidR so the solution I used was LAS2LAS to merge all the original un-projected LAS files into a single LAS file, project the new merged LAS, then use lidR for the rasterization for the whole area.

Hope this is useful for someone.

library(terra) # write raster files
library(lidR)
library(tictoc) #time script
library(hutils) # check if output folder exists and makes if not

# lastools path
exe_path_lastools <- "C:/LAStools/bin/"

# input/output 
in_dir = "D:/las_folder/" 
in_dir_filter = paste0(in_dir,"*.laz")

## ----------------------------------------------------------------------------
# set csr and convert to las v1.4 (larger point size limit per file)
# make single merged las file
## ----------------------------------------------------------------------------
# CRS projection
crs_code_src = 3006
crs_code_src_rh2000 = 5613
crs_code_target = 3011

out_dir = paste0(in_dir,"_",crs_code_target,.Platform$file.sep)
out_file_las = paste0(out_dir,.Platform$file.sep,"_merged.laz")
out_file_dem = paste0(out_dir,.Platform$file.sep,"_Haninge_DEM.tif")

# make output folder if it doenst exist
provide.dir(out_dir)

# lastools command
batchline_convert_las14 <- str_glue("{exe_path_lastools}las2las.exe -i {in_dir_filter} -keep_class 2 -set_version 1.4 -epsg {crs_code_src} -vertical_epsg {crs_code_src_rh2000} -target_epsg {crs_code_target} -target_elevation_meter -merged -o {out_file_las}")

# run lastools command
system(batchline_convert_las14)

toc()
print("las2las, done. starting rasterize terrain")
## ----------------------------------------------------------------------------
# make raster with lidr
## ----------------------------------------------------------------------------
# make dtm
las_data <- readLAS(out_file_las)
dtm <- rasterize_terrain(las_data, res = 1, tin())

# save dtm as raster
terra::writeRaster(dtm, out_file_dem, filetype = "GTiff", 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.