To aid in quality control of a set of LAS files, I would like to write out all errors/warnings from lascheck()
, for each LAS file (i.e. so not the LAScatalog
implementation of lascheck(()
). I'm looking for any tips to extract lascheck()
warnings while looping through the entire list.
-
1lascheck returns nothing. It only prints. What you are asking is more a redesign of the function which is a fair feature request.– JRRFeb 24, 2020 at 17:31
1 Answer
Anwser for lidR version 2.x.y
lascheck()
does not return anything. It only prints. It might be seen as a design mistake and it is fair to think that. However we can find a workaround by capturing the standard output. lascheck()
prefixes what is considered as a warning with the symbol ⚠ (\u26A0
) and what is considered an error with ✗ (\u2717
). You can grep
these symbols.
library(lidR)
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las = readLAS(LASfile)
las$ReturnNumber[1] <- 0L # Introduce warnings
las@header@PHB$`Point Data Format ID` <- 12L # Introduce errors.
check = capture.output(lascheck(las))
warn_pos = grep("\u26A0", check)
warns = trimws(check[warn_pos])
warns
#> [1] "⚠ Invalid data: 1 points with a return number equal to 0 found."
#> [2] "⚠ 'PointSourceID' attribute is not populated."
#> [3] "⚠ 'EdgeOfFlightline' attribute is not populated."
#> [4] "⚠ Invalid file: the header states the file contains 55756 returns numbered '1' but 55755 were found."
err_pos = grep("\u2717", check)
errs = trimws(check[err_pos])
errs
#> [1] "✗ Invalid data: ReturnNumber is not an unsigned integer"
#> [2] "✗ Invalid header: The point data format 12 is not part of the LAS specifications."
#> [3] "✗ Invalid file: the data contains a 'gpstime' attribute but point data format is not set to 1, 3, 6, 7 or 8."
Created on 2020-02-24 by the reprex package (v0.3.0)
Answer for lidR version 3+ (to be released)
las_check()
has an option print = FALSE
las_check(las, FALSE)
#> $warnings
#> [1] "Invalid data: 1 points with a return number equal to 0 found."
#> [2] "'PointSourceID' attribute is not populated."
#> [3] "'EdgeOfFlightline' attribute is not populated."
#> [4] "Invalid file: the header states the file contains 55756 returns numbered '1' but 55755 were found."
#>
#> $errors
#> [1] "Invalid data: ReturnNumber is not an unsigned integer"
#> [2] "Invalid header: The point data format 12 is not part of the LAS specifications."
#> [3] "Invalid file: the data contains a 'gpstime' attribute but point data format is not set to 1, 3, 6, 7 or 8."
-
1I had to modify the grep search string to: warn_pos = grep("+26A0", check) and err_pos = grep("+2717", check)– Ray JFeb 24, 2020 at 18:11
-