I would like to filter the points that are used in a canopy height model. In particular I would like filter out any points whose height is over 200 feet. I've tried the code below but when I plot the difference between my normalized and filtered tiles, they are exactly the same and there are still z values above 200 feet. I must be using the opt_filter
command incorrectly, or have chosen the wrong mechanism.
library(lidR)
indata <- suppressWarnings(readLAScatalog ("c:/test/laz"))
# Normalize point cloud data
opt_output_files(indata) <- "c:/test/norm/norm_{XRIGHT}_{YBOTTOM}"
normalized_las <- normalize_height (indata, tin(), na.rm=TRUE)
# Keep points where height is between 0 and 200 feet
filtered_las <- suppressWarnings(readLAScatalog ("c:/test/norm/"))
opt_filter (filtered_las) <- "Z>=0 and Z<=200"
opt_output_files(filtered_las) <- "c:/test/filt/filt_{XRIGHT}_{YBOTTOM}"
filt_ctg <- catalog_retile(filtered_las)
# Now read in the same filtered and normalized tile
filt1 <- 'c:/test/filt/filt_2885000_2320000.las'
filtlas <- readLAS(filt1)
norm1 <- 'c:/test/norm/norm_2885000_2320000.las'
normlas <- readLAS(norm1)
# Visualize difference between filtered and unfiltered points
par(mfrow=c(2,2))
boxplot(normlas@data$Z, ylim = c(-10,1000), ylab = "Height (ft)", main = "Before Filtering")
boxplot(filtlas@data$Z, ylim = c(-10,1000), ylab = "Height (ft)", main = "After Filtering")
hist(normlas@data$Z, xlim=c(-2,1000), xlab = "Height (ft)", main = "Before Filtering")
hist(filtlas@data$Z, xlim=c(-2,1000), xlab = "Height (ft)", main = "After Filtering")