diff --git a/NEWS.md b/NEWS.md index aa82cd6b..3714cf82 100755 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ If you are viewing this file on CRAN, please check [the latest news on GitHub](h - Fix: #771 read VPC files with absolute path - Enhance: `crs()` `is.empty()` and `area()` are now inherits from `terra` and no longer clash with `terra`. +- Enhance: #776 `readLAScatalog` can skipped corrupted files ## lidR v4.1.2 (Release date: 2024-07-09) diff --git a/R/io_readLAScatalog.R b/R/io_readLAScatalog.R index 7a49ec61..6eb5533c 100644 --- a/R/io_readLAScatalog.R +++ b/R/io_readLAScatalog.R @@ -101,7 +101,13 @@ readLAScatalog <- function(folder, progress = TRUE, select = "*", filter = "", c headers <- lapply(files, function(x) { - header <- rlas:::lasheaderreader(x) + header <- rlas:::lasheaderreader(x) + if (length(header) == 0) + { + warning(paste0("Corrupted file ", x, " is not readable and was skipped in the LAScatalog")) + return(NULL) + } + header <- LASheader(header) PHB <- header@PHB names(PHB) <- phblab @@ -136,6 +142,8 @@ readLAScatalog <- function(folder, progress = TRUE, select = "*", filter = "", c }) } + rm = sapply(headers, is.null) + files = files[!rm] headers <- data.table::rbindlist(headers) headers$filename <- files data.table::setDF(headers)