How to filter point cloud by flightline in R?

This is not natively possible yet in lidR! But R is a programming language so you can write your own algorithm to achieve this task. If you can do that please share with the community it could be useful ;-). I think LAStools has such tool.


Update:

Essentially, I am looking to remove the overlapping points so as to produce a homogeneous point cloud with no scanline overlaps.

Besides thinning (Thinning large LiDAR point cloud?), if the .las file is classified (or flagged) as 'overlapping' points one can filter those out on-the-fly while importing data in R.

  • For versions LAS 1.0 to 1.3 (point formats 0 to 5) overlapping points have their own class code, usually class 12. They can be filtered out with -drop_class 12 as reported in your answer here.

  • For version LAS 1.4 (point formats 6 to 10), it was introduced a group of classification flags, being one of them Overlap. This flag allows points to be flagged 'overlap' while also labeled with a different class code. For example, it can be an overlapping point (flagged) and a ground point (class 2). For those types of files, do the following*:

library(lidR) 
file.path <- system.file("extdata", "Megaplot.laz", package="lidR")
lidar <- readLAS(file.path, filter = "-drop_overlap") #LAS 1.4 (point formats 6 to 10) which has overlapping points set to 1 in the Classification Flag 'Overlap'.

Other methods and software for removing overlapping points are reported in Open source approach to classifying and removing LiDAR points from overlapping scans?


Original answer:

How to filter point cloud by flightline in R?

As pointed by JRR's answer, it is not possible yet using native filters from readLAS function available in the lidR package (see rlas:::lasfilterusage()).

So, the current alternative is to use lasfilter. See below:

library(lidR) 
file.path <- system.file("extdata", "Megaplot.laz", package="lidR")
lidar <- readLAS(file.path)
lasflightline(lidar, dt = 30)
#check how many flight lines (there should be at least two, so this exercise makes sense)
unique(lidar@data$flightlineID)

for (i in c(1:2)){
assign(paste("lidar.flightline.",i,sep=""), lasfilter(lidar, flightlineID == i))
}

rm(file.path,i,lidar)