I am normalizing a set of LAS files. In the function after normalize_height
, I filter out vegetation with heights below 0 using filter_poi
, and returning this as input to catalog_apply
. However, I would also like to save vegetation with heights below 0 as a check.
It doesn't appear possible to return 2 objects (veg_ge_0 and veg_lt_0). It is also not possible to use opt_filter
outside of the function since this seems to work on the input to the function and not on the output.
Is there a more efficient way (like returning 2 objects from the function to use in a second catalog_apply
) other than creating a new function combined with catalog_apply
for filtering the negatives?
library(lidR)
setwd("D:/Projects2021/p2021_0101_lidR_vs_LasTools/")
dirLASfiles_Raw <- "LasFiles__original/"
dirLASfiles_Norm <- "LasFiles_normalizedWith_lidR_wTIN/"
interpolationMethod <- tin('', extrapolate = knnidw(k = 10, p = 2, rmax = 50))
ctg <- readLAScatalog(dirLASfiles_Raw,
progress = TRUE,
filter = "-drop_withheld -drop_overlap -drop_z_below -1")
groundWaterVeg_filterAndNormalization_Function = function(chunk) {
lasChunk = readLAS(chunk)
if (is.empty(lasChunk)) return(NULL)
ground <- filter_poi(lasChunk, Classification == 2L | Classification == 9L)
if (is.empty(ground))
return(NULL)
vegetation <- filter_poi(lasChunk, Classification == 3L | Classification == 4L | Classification == 5L)
if (is.empty(vegetation))
return(NULL)
lasNorm <- normalize_height(lasChunk, algorithm = interpolationMethod, na.rm = TRUE, use_class = c(2L, 9L))
#lasNormFltrNegVeg <- filter_poi(lasNorm, ((Classification == 3L | Classification == 4L | Classification ==5L) & (Z < 0)), buffer == 0)
lasNormFltr <- filter_poi(lasNorm, ((Classification == 3L | Classification == 4L | Classification ==5L) & (Z >= 0 & Z <= 30)) | (Classification == 2L | Classification == 9L), buffer == 0) #! LASFilter is depracated. use Filter_POi
return(lasNormFltr) #,lasNormFltrNegVeg)
}
opt_chunk_buffer(ctg) <- 25
opt_output_files(ctg) <- paste(dirLASfiles_Norm,"{ORIGINALFILENAME}_normTIN_vegge0PlusGround", sep = "")
mylasCatalogueNorm <- catalog_apply(ctg, groundWaterVeg_filterAndNormalization_Function)
lasNormFltr
+lasNorm
+ground
+vegetation
in a single shot ?lasNormFltrNegVeg