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).
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))
From #550 by @poornima-s10
clip2_denoise.las