r-lidar / lidR

Airborne LiDAR data manipulation and visualisation for forestry application
https://CRAN.R-project.org/package=lidR
GNU General Public License v3.0
612 stars 133 forks source link

rasterize_terrain() only outputs the last tile of LAScatalog #729

Closed natedailey7 closed 1 year ago

natedailey7 commented 1 year ago

When I use rasterize_terrain() to create a DTM based on a LAScatalog, only the last tile is shown in my output. The same happens when I use normalize_height(). This is a continuation of a GIS Stack Exchange post here.

I uploaded my data (2 las files) along with my script to Google Drive here.

install.packages("lidR")
library(lidR)

WORKING_DIRECTORY <- "path"
setwd(WORKING_DIRECTORY)

# Assign relative paths for las files and R Outputs. 
LAS_CATALOG <- "data"
R_OUTPUT_FILES <- "R_Outputs"

# read the two las files
ctg <- readLAScatalog(LAS_CATALOG)

plot(ctg)

image

# Assign location for output files and allow overwriting. 
opt_output_files(ctg) <- R_OUTPUT_FILES
ctg@output_options$drivers$SpatRaster$param$overwrite <- TRUE

# create dtm. For me, only the last tile is shown in the plot. 
dtm <- rasterize_terrain(ctg, algorithm=knnidw(), overwrite=TRUE)
plot(dtm)

image

# Normalize height -- again, only the last tile is processed for me. 
norm <- normalize_height(ctg, tin())
plot(norm)

image

Let me know if you have any ideas or suggestions -- thank you.

Jean-Romain commented 1 year ago
R_OUTPUT_FILES <- "R_Outputs"
opt_output_files(ctg) <- R_OUTPUT_FILES

Your path is not templated. So it processes the first LAS file, writes it in R_ouput.tif then the second LAS file also in R_output.tif and erases the first raster. Use the name of the LAS files to name your rasters

R_OUTPUT_FILES <- "{ORIGINALFILENAME}_chm"
opt_output_files(ctg) <- R_OUTPUT_FILES

I could have answered on stack exchange if you provided a reproducible code :wink: :

natedailey7 commented 1 year ago

AMAZING!! Worked perfectly -- Thank you so much 😄