LoginSignup
5
1

More than 1 year has passed since last update.

古いlasデータをLAStoolsで最新版にアップグレードして、さらにLAZに圧縮にしてファイルサイズを1/4以下にする

Last updated at Posted at 2022-06-27

LASデータのバージョンって?

以下の記事で紹介したLASデータですが、記載の通りバージョン1.0~1.4まであり、v1.4が最新版になります。

v1.4が策定されたのは2013年のはずなので、もう10年ほど経っていますが、日本でオープンに公開されているデータを見ると、v1.2やv1.3もまだ多く残っています。

基本的にはv1.4と比較して、ヘッダーや属性などに持てる情報少なくなってしまうため、あまりメリットはありません。

今回は以下で紹介したLAStoolsの中から、無償で利用できるlas2lasを利用して、v1.2のデータをv1.4に昇格させて、さらにLAZに圧縮し、データサイズを30パーセント程度まで高圧縮していきましょう!

データのダウンロード

例の如くG空間情報センターからデータをダウンロードしていきましょう。

地図をズームし、適当な箇所のデータをダウンロードします。

image.png

今回は、08OF1348という地区のデータをダウンロードしました。

LAStoolsのlasinfoでメタ情報を確認します。
このコマンドでversionは1.2、point data formatは3だということが分かりますね。
lasinfoを使うと基本的なLASのメタ情報は全て取得できます。

❯ lasinfo 08OF1348.las
lasinfo (220613) report for '08OF1348.las'
reporting all LAS header entries:
  file signature:             'LASF'
  file source ID:             0
  global_encoding:            1
  project ID GUID data 1-4:   00000000-0000-0000-0000-000000000000
  version major.minor:        1.2
  system identifier:          'Aero Asahi Corp.,'
  generating software:        'LAS Tool'
  file creation day/year:     65/2020
  header size:                227
  offset to point data:       229
  number var. length records: 0
  point data format:          3
  point data record length:   34
  number of point records:    10647410
  number of points by return: 5951724 2357532 1336198 670565 331391
  scale factor x y z:         0.001 0.001 0.001
  offset x y z:               -0 -0 -0
  min x y z:                  55199.840 -124500.130 58.430
  max x y z:                  55600.070 -124199.790 103.600
the header is followed by 2 user-defined bytes
reporting minimum and maximum for all LAS point record entries ...
  X            55199840   55600070
  Y          -124500130 -124199790
  Z               58430     103600
  intensity         444      65535
  return_number       1          5
  number_of_returns   1          5
  edge_of_flight_line 0          0
  scan_direction_flag 0          1
  classification      1          2
  scan_angle_rank   -14         14
  user_data           1          1
  point_source_ID    28         83
  gps_time 259119985.930357 260069306.731555
  Color R 7168 65280
        G 11776 65280
        B 256 65280
WARNING: there is coordinate resolution fluff (x10) in Z
number of first returns:        5951724
number of intermediate returns: 2258126
number of last returns:         6041380
number of single returns:       3603820
overview over number of returns of given pulse: 3603820 2035805 1995189 1680537 1332059 0 0
histogram of classification of points:
         7131131  unclassified (1)
         3516279  ground (2)

LAStoolsでデータ変換

LAStoolsでv1.4・point_formatを7に変換しつつ、lazに圧縮していきましょう。
LAStoolsでは同時に行うことが可能です。

❯ las2las -i 08OF1348.las \
    -o 08OF1348_1_4.laz \
    -remove_vlrs_from_to 1 2 \
    -set_version 1.4 \
    -set_point_type 7

今回のデータはファイルサイズが少ないので、サクッと変換が終わるかと思います。
08OF1348_1_4.lazというファイルができていれば成功です。

データを確認する

LAStoolsはLAZファイルもそのまま読み込むことが可能なので、変換したファイルをlasinfoで確認しましょう。
versionが1.4、point data formatが7のLAZファイルになっているのが確認できるかと思います。

lasinfo 08OF1348_1_4.laz
lasinfo (220613) report for '08OF1348_1_4.laz'
reporting all LAS header entries:
  file signature:             'LASF'
  file source ID:             0
  global_encoding:            1
  project ID GUID data 1-4:   00000000-0000-0000-0000-000000000000
  version major.minor:        1.4
  system identifier:          'LAStools (c) by rapidlasso GmbH'
  generating software:        'las2las (version 220613)'
  file creation day/year:     65/2020
  header size:                375
  offset to point data:       375
  number var. length records: 0
  point data format:          7
  point data record length:   36
  number of point records:    0
  number of points by return: 0 0 0 0 0
  scale factor x y z:         0.001 0.001 0.001
  offset x y z:               -0 -0 -0
  min x y z:                  55199.840 -124500.130 58.430
  max x y z:                  55600.070 -124199.790 103.600
  start of waveform data packet record: 0
  start of first extended variable length record: 0
  number of extended_variable length records: 0
  extended number of point records: 10647410
  extended number of points by return: 5951724 2357532 1336198 670565 331391 0 0 0 0 0 0 0 0 0 0
LASzip compression (version 3.4r3 c3 50000): POINT14 3 RGB14 3
reporting minimum and maximum for all LAS point record entries ...
  X            55199840   55600070
  Y          -124500130 -124199790
  Z               58430     103600
  intensity         444      65535
  return_number       1          5
  number_of_returns   1          5
  edge_of_flight_line 0          0
  scan_direction_flag 0          1
  classification      1          2
  scan_angle_rank   -14         14
  user_data           1          1
  point_source_ID    28         83
  gps_time 259119985.930357 260069306.731555
  Color R 7168 65280
        G 11776 65280
        B 256 65280
  extended_return_number          1      5
  extended_number_of_returns      1      5
  extended_classification         1      2
  extended_scan_angle         -2333   2333
  extended_scanner_channel        0      0
WARNING: there is coordinate resolution fluff (x10) in Z
number of first returns:        5951724
number of intermediate returns: 2258126
number of last returns:         6041380
number of single returns:       3603820
overview over extended number of returns of given pulse: 3603820 2035805 1995189 1680537 1332059 0 0 0 0 0 0 0 0 0 0
histogram of classification of points:
         7131131  unclassified (1)
         3516279  ground (2)

laspyで確認する

pythonのlaspyパッケージでは、拡張をインストールすることでLAZファイルを直接読み込めるようになっています。
以下の記事でlaspyのcondaでのインストールや使い方を紹介していますが、condaでは拡張機能が公開されていないので、インストール済みの方は一回アンインストールしたのち、pypiから再インストールしましょう。

インストール済みの方は、condaの仮想環境内で以下のコマンドを実行することで、condaでインストールしたlaspyを削除しつつ、pipでインストールしたlaspyをcondaの仮想環境で実行することができます。

conda uninstall laspy
pip install laspy[lazrs,laszip]

インストールできたら読み込んでいきましょう!
LAZが読み込める上、バージョン1.4でpointformatが7になったのが確認できると思います!

import laspy as lp

file_path = "08OF1348_1_4.laz"
laz = lp.read(file_path)

laz.header
# <LasHeader(1.4, <PointFormat(7, 0 bytes of extra dims)>)>

ファイルサイズもグッと減っていますね!
las: 362MB
laz: 80MB

import os

print(os.path.getsize("08OF1348.las"))
print(os.path.getsize("08OF1348_1_4.laz"))
# 362012169
# 79983563

終わりに

LAStoolsとlaspyを使いこなせるとLAZファイルを手軽に作れる上、そのまま操作できるため、作業効率がグッと上がりますね!
みなさんもうまいこと利用してみてください!

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1