following up on this question: Capture and parse output of lascheck from lidR... (while lidR 3 is in development, I thought I'd continue with a workaround.)
I'm using catalog_apply
to perform lascheck
on individual las files in the catalog. I'm getting the right output for warnings/errors, but I can't identify the name of the las file (chunk) because although the warnings/errors are there in the output of lascheck
, the name isn't.
However, a list of names is available in the LASCatalog. I would like to extract the corresponding name, but I can't increment a variable to count (for reasons of scope I think). I.e. capture.output(ctg@data$filename[x])
where x is position of the name in the list.
E.g. the following code does return the warnings/errors but x
gets stuck at 1.
library(lidR)
ctg <- readLAScatalog("D:/Projects2020/Sherbrooke/") #, progress = TRUE, list.files())
x <- 0
errwrn <- function(chunk)
{
las = readLAS(chunk)
if (is.empty(las)) return(NULL)
las@header@PHB$`Point Data Format ID` <- 12L # Introduce errors.
ew <- capture.output(lascheck(las))
err_pos = grep("+2717", ew)
errs = ew[err_pos]
warn_pos = grep("+26A0", ew)
warns = ew[warn_pos]
x <- x + 1
lasName <- capture.output(ctg@data$filename[x])
ews = c(x, lasName, errs, warns)
return (ews)
}
lascheckList <- catalog_apply(ctg, errwrn)
Can anyone see how I could increment x? Or maybe I should use a loop to go through each file in the directory, bypassing the use of a catalog?