How do I create a custom algorithm for decimate_points() in lidR analogous to the highest() algorithm but that selects the lowest points?

decimate_points(las, lowest(2))

I know that lidR allows to add custom algorithms as it was suggested by @JRR in this question: How -thin_with_grid works?

1 Answer 1


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


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

#> 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))

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.