1

I have a TLS point cloud which were classified into ground (class 2) and unclassified (class 1).

lasinfo (190812) report for 'infile.laz'
reporting all LAS header entries:
  file signature:             'LASF'
  file source ID:             0
  global_encoding:            0
  project ID GUID data 1-4:   00000000-0000-0000-0000-000000000000
  version major.minor:        1.2
  system identifier:          'LAStools (c) by rapidlasso GmbH'
  generating software:        'las2las (version 190623)'
  file creation day/year:     50/2019
  header size:                227
  offset to point data:       337
  number var. length records: 1
  point data format:          3
  point data record length:   34
  number of point records:    52463936
  number of points by return: 52463936 0 0 0 0
  scale factor x y z:         0.00025 0.00025 0.00025
  offset x y z:               695760.719696044921875 6106543.521759033203125 0
  min x y z:                  695760.73345 6106543.76051 -0.03700
  max x y z:                  695938.96420 6106715.68576 14.72325
variable length header record 1 of 1:
  reserved             43707
  user ID              'LASF_Projection'
  record ID            34735
  length after header  56
  description          'GeoKeyDirectoryTag (mandatory)'
    GeoKeyDirectoryTag version 1.1.0 number of keys 6
      key 1025 tiff_tag_location 0 count 1 value_offset 2 - GTRasterTypeGeoKey: RasterPixelIsPoint
      key 2052 tiff_tag_location 0 count 1 value_offset 9001 - GeogLinearUnitsGeoKey: Linear_Meter
      key 2054 tiff_tag_location 0 count 1 value_offset 9102 - GeogAngularUnitsGeoKey: Angular_Degree
      key 2060 tiff_tag_location 0 count 1 value_offset 9102 - GeogAzimuthUnitsGeoKey: Angular_Degree
      key 3076 tiff_tag_location 0 count 1 value_offset 9001 - ProjLinearUnitsGeoKey: Linear_Meter
      key 4099 tiff_tag_location 0 count 1 value_offset 9001 - VerticalUnitsGeoKey: Linear_Meter
LASzip compression (version 3.4r1 c2 50000): POINT10 2 GPSTIME11 2 RGB12 2
reporting minimum and maximum for all LAS point record entries ...
  X                  55     712978
  Y                 955     688656
  Z                -148      58893
  intensity           0      65432
  return_number       1          1
  number_of_returns   1          1
  edge_of_flight_line 0          0
  scan_direction_flag 0          0
  classification      1          2
  scan_angle_rank     0          0
  user_data           0          0
  point_source_ID    64         64
  gps_time 194.000000 21782810.000000
WARNING: range violates GPS week time specified by global encoding bit 0
  Color R 0 61696
        G 0 59904
        B 0 64256
number of first returns:        52463936
number of intermediate returns: 0
number of last returns:         52463936
number of single returns:       52463936
overview over number of returns of given pulse: 52463936 0 0 0 0 0 0
histogram of classification of points:
        34352771  unclassified (1)
        18111165  ground (2)

I want to drop ground class 2 and keep class 1 in analysis:

> las_sf = readLAS("infile.laz", select = "xyzc", filter = "-keep_first -drop_z_below 0 ")

However, it doesn't seem to work:

> npoints(las_sf)
[1] 52463535

I am using lidR_3.0.1

How can I work around this?

5
  • I can see you have LASTools, try LAS2LAS -keep_class 1 see cs.unc.edu/~isenburg/lastools/download/las2las_README.txt and find (Ctrl + F) the line Filter points based on classifications or flags, this can be used to extract the class 1 from a whole folder of LAS or LAZ (or even txt) into a new, empty, folder as LAS, LAZ (or even TXT). Commented Jun 22, 2020 at 0:20
  • Thanks @MichaelStimson. I don't have lastools license unfortunately. Therefore, I am trying to use lidR. lasinfo is available for free, that's why I used it.
    – Sher
    Commented Jun 22, 2020 at 0:21
  • 1
    LAS2LAS may also be one of the free tools, or it may be limited to 50k points or not LAZ. Try it and see if it works; if you are going to work with LiDAR data a lot please consider purchasing a license. The options for lidR rdrr.io/cran/lidR/man/readLAS.html in the example show very similar options to LASTools, try changing your filter = "-keep_class 1" and see if that does what you want, your current filter will return all points above 0 elevation as they're all flagged as first (see your number of returns in LASInfo). Commented Jun 22, 2020 at 0:34
  • Thank you very much @MichaelStimson. filter = "-keep_class 1" worked. Surprisingly, keep_class is not given in lidR document. I thought "-keep_first" means to keep class not return.
    – Sher
    Commented Jun 22, 2020 at 0:41
  • Excellent, now please answer your own question, as this is undocumented your answer will be invaluable to future users of lidR. Commented Jun 22, 2020 at 0:49

2 Answers 2

3

lidR uses rlas to read LAS/LAZ files. rlas is a wrapper of LASlib and LASzip in R meaning that all the filters in LAStools are also in lidR

You can use filter = "-drop_class 2"

Check the documentation of readLAS to find all the filters with :

readLAS(filter = "-help")
1

Following the suggestion of Michael Stimson, "filter ("-keep_class 1")" kept only class 1 points and dropped the class 2. I also tested the functionality of some filters in LAS2LAS if they work in lidR and functions such as drop_z, -last_only also worked which is great, however not listed in lidR documentation. It would be great to see lidR keep class, lidR drop z, lidR last only filters in future versions of lidR documentation.

3
  • If you have some free time perhaps try some of the other filters mentioned in LAS2LAS and see if they work also, edit the functional/dysfunctional query switches into your answer. If the lidR documentation is a bit sketchy a canonical list of filters that work would be useful and you may even end up with popular question notoriety. Answers are searchable so anyone that Googles "lidR keep class" will lead them here. Commented Jun 22, 2020 at 2:27
  • Thanks Michael Stimpson, I tested some other filters from LAS2LAS and they worked which is amazing. I added them to the response.
    – Sher
    Commented Jun 22, 2020 at 4:01
  • All the filters are accessible in lidR. Check out the documentation ;-)
    – JRR
    Commented Jun 22, 2020 at 16:20

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.