lidR
accepts "plugins". How to make plugins is partially documented in a dedicated chapter of the book. It is not yet fully part of public API but you can safely use it if you are not creating a CRAN package.
Notice that a C++ based version of lowest()
will be available in lidR 3.1.2
library(lidR)
lowest <- function(res = 1) {
stopifnot(is.numeric(res), length(res) == 1L, res > 0)
f <- function(las) {
r <- grid_metrics(las, ~.I[which.min(Z)], res = res) # .I[] is a data.table feature
return(na.omit(r[])) # Return the id of the points of interest
}
class(f) <- lidR:::LIDRALGORITHMDEC # Using ::: because not public yet
return(f)
}
lowest(2)
#> Object of class lidR algorithm
#> Algorithm for: point cloud thinning
#> Designed to be used with: decimate_points
#> Native C++ parallelization: no
#> Parameters:
#> - res = 2 <numeric>
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las <- readLAS(LASfile)
thinned <- decimate_points(las, lowest(4))
plot(thinned)
