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
601 stars 131 forks source link

Irrelevant CHM or error for some specific resolution #552

Closed Jean-Romain closed 2 years ago

Jean-Romain commented 2 years ago

From #550 by @poornima-s10

I have recently started using lidR and have run into some issues with rasterize_canopy. [...] I have a ground classified/normalised point cloud. I am using LAScatalog mainly but in this case have tested both LAScatalog and LAS objects with rasterize_canopy (to rule out any issues with my LAScatalog chunks).

clip2_denoise.las

library(lidR)

las = readLAS("clip2_denoised.las")
mycsf <- csf(sloop_smooth=FALSE, cloth_resolution = 0.2, iterations = 500, class_threshold = 0.1)
gnd_las <- classify_ground(las, mycsf)
norm_las <- normalize_height(gnd_las, knnidw(k=10, p=2))

# this is ok in terra/raster - pulse spacing in clip is 0.03 m. In original file it's 0.02 m.
chm = rasterize_canopy(norm_las, res=0.09, p2r(0.2)) 

# recreate issue seen on original file which had pulse spacing 0.02 m with rasterize_canopy res=0.10
chm = rasterize_canopy(norm_las, res=0.06, p2r(0.2)) 
#>Error: [] lengths of of cells and values do not match

# change to raster
options(lidR.raster.default = "raster")
chm = rasterize_canopy(norm_las, res=0.06, p2r(0.2)) 
# No error with raster but output is incorrect.
plot(chm, col=height.colors(50))

Rplot

Jean-Romain commented 2 years ago

Fixed.