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

las-files without Points #711

Closed PiusHauenstein closed 8 months ago

PiusHauenstein commented 11 months ago

if las_check should analyze an empty las-file, it crashes:

ctg <- readLAScatalog("D:\\LiDAR2019\\laz_Filter_GP_Cleaned")
las_check(ctg, deep = TRUE)
#> An error occurred when processing the chunk 8. Try to load this chunk with:
#>  chunk <- readRDS("C:\Users\phca\AppData\Local\Temp\2\Rtmp6BsQIE/chunk8.rds")
#>  las <- readLAS(chunk)
#> [ext] invalid extent
#> Error in names(out) <- basename(las@data[["filename"]]) : 
#>   'names' attribute [1614] must be the same length as the vector [7]
#> In addition: There were 36 warnings (use warnings() to see them)

Empty las-files can happen, if you process a chunk of files previously for example with lastools with a filter condition

Jean-Romain commented 11 months ago

Please share a empty file. I cannot produce an empty file with las2las. It does not write empty files. I don't know how you produced an empty file. Thanks

PiusHauenstein commented 11 months ago

You can produce one with "lasduplicate -keep_class xx", xx must be a not existing class in the input file

empty.zip

Jean-Romain commented 11 months ago

Ok the problem is less serious than expected. I though that it crashed when reading 0 point but it only produced a regular errors and stop.

f = "issue 711/empty.las"
las = lidR::readLAS(f)
lidR::las_check(las)
Jean-Romain commented 11 months ago

You can get rid of empty files to fix you problem upstream. This is what I will implement as a first layer of protection. I will also exit las_check() early for 0 point LAS objects

ctg = ctg[ctg$Number.of.point.records > 0,]
Jean-Romain commented 8 months ago

fixed