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
582 stars 130 forks source link

checks on empty clouds #770

Closed spono closed 1 month ago

spono commented 1 month ago

Ciao JR, just a quick question: I stepped for the first time into rlas::is_empty_point_cloud() noticing that it behaves in the opposite way to lidR::is.empty(). All data processing seems to go properly but, in any case, I prefer to ask: is that meant to be like that?

LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las <- readLAS(LASfile, select = "xyz")
las = filter_poi(las, Z > 50)

rlas::is_empty_point_cloud(las)

lidR::is.empty(las)
Jean-Romain commented 1 month ago

All these rlas functions are not meant to be used by users. They are used internally by lidR to handle LAS specification compliance. First the function takes a header (list) as input and not a point cloud (data.frame) and certainly no a LAS from lidR. rlas knows nothing about lidR. Second the goal of rlas::is_empty_point_cloud is not to know if the point cloud if empty but rather to pass or fail a test of LAS specification compliance. Having 0 point is not a failure so it return TRUE

LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las <- readLAS(LASfile, select = "xyz")
las = filter_poi(las, Z > 50)

rlas::is_empty_point_cloud(as.list(header(las)))
#> TRUE
rlas::is_empty_point_cloud(as.list(header(las)), "warning")
#> Warning : Invalid header: the header state there are 0 point in the file 
rlas::is_empty_point_cloud(as.list(header(las)), "stop")
#> Error : Invalid header: the header state there are 0 point in the file
spono commented 1 month ago

ok, I imagined there was something "bigger" behind, but checkin the documentation I didn't get what you explained. thanks!