日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python读文件en_python 点云las、laz文件的读取、写入、压缩

發布時間:2023/12/15 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python读文件en_python 点云las、laz文件的读取、写入、压缩 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. python las讀取與寫入

用laspy庫: https://pypi.org/project/laspy/

獲取las、laz的規格、點數據格式,點數據的具體字段名稱,具體的點數據

解析las、laz頭文件區、點數據區的所有字段

參考:https://readthedocs.org/projects/laspy/

參考:https://pylas.readthedocs.io/en/latest/installation.html

pip install laspy

from laspy.file import File

def main():

f = File("E:/dataTes/1001140020191217.las", mode='r')

# 查看點云的點格式及字段名稱

print('\nPoint Of Data Format: ', f.header.data_format_id)

print("\tExamining Point Format: ", end=" ")

for spec in f.point_format:

print(spec.name, end=", ")

print('\noffset: ', f.header.offset) # 偏移量

print('scale: ', f.header.scale) # 比例因子

print('min: ', f.header.min) # x、y、z 的最小值

print('max: ', f.header.max) # x、y、z 的最大值

print('file_signature: ', f.header.file_signature) # 文件標識

print('Point Of Data Format: ', f.header.data_format_id) # 點格式

print('data_record_length: ', f.header.data_record_length) # 點個數

print('FileCreateDay+Year: ', f.header.date)

print()

print('f.x: ', f.x)

print('f.y: ', f.y)

print('f.z: ', f.z)

print('f.intensity: ', f.intensity)

print('f.gps_time: ', f.gps_time)

print('f.raw_classification: ', f.raw_classification)

print()

# print('f.user_data: ', f.user_data)

# print('f.flag_byte: ', f.flag_byte)

# print('f.Color: ', f.red, f.green, f.blue)

# print('file_source_id: ', f.header.file_source_id)

# print('Major_Minor version: ', f.header.version, str(f.header.version_major) + '.' + str(f.header.version_minor))

# print('Generation Software: ', f.header.software_id)

# print('system_id: ', f.header.system_id)

# print('Header Size: ', f.header.header_size)

# print('file_global_encoding: ', f.header.global_encoding)

# print('gps_time_type: ', f.header.gps_time_type)

# print('guid: ', f.header.guid)

print()

# print('f.edge_flight_line: ', f.edge_flight_line)

# print('f.return_num: ', f.return_num)

# print('f.classification: ', f.classification)

# print('f.scan_angle_rank: ', f.scan_angle_rank)

# print('f.scan_dir_flag: ', f.scan_dir_flag)

# print('f.num_returns: ', f.num_returns)

# print('pt_src_id: ', f.pt_src_id)

f.close()

if __name__ == "__main__":

main()

2. las的壓縮,.las轉.laz,.laz轉.las

las點云的無損壓縮:將.las轉為.laz,壓縮率可達15%,空間占用減少85%;

需要倆個模塊

pip install pylas

pip install lazrs

參考:https://gis.stackexchange.com/questions/332366/reading-laz-file-in-python-directly

pylas官方文檔: https://pylas.readthedocs.io/en/latest/installation.html

import pylas

import time

# laz 轉 las

end0 = time.time()

las = pylas.read('E:/dataTes/1001117.laz')

las = pylas.convert(las)

las.write('E:/dataTes/1001117_laz2las.las')

end1 = time.time()

print("laz2las 耗時:%.2f秒" % (end1 - end0))

print('------------end1------------')

# las 轉 laz

las1 = pylas.read('E:/dataTes/1001147.las')

las1 = pylas.convert(las1)

las1.write('E:/dataTes/1001147_las2laz.laz')

end2 = time.time()

print("las2laz 耗時:%.2f秒" % (end2 - end1))

print('---------end----------')

3. laspy讀取.laz

參考:https://stackoverflow.com/questions/49500149/laspy-cannot-find-laszip-when-is-installed-from-source-laszip-is-in-path

有用到(lasTools的laszip.exe以及dll)

windows下需要往Path環境變量里添加自己下載的lasTools的bin目錄;

lasTools下載: https://github.com/m-schuetz/LAStools

from laspy.file import File

import os

def main():

# 最重要的后邊要有 E:\Las\LAStools\bin; lasTools中laszip.exe的路徑

print(os.environ["PATH"])

# E:\python\lib\site-packages\pywin32_system32;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;D:\jdk181\bin;D:\hadoop-common-2.2.0\bin;C:\Windows\vrv\common\vSSLFltSvc;D:\apache-maven-3.5.3\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;D:\dnProject\scala-2.11.8\scala-2.11.8\bin;D:\svnSsrver\bin;D:\apache-maven-3.5.3\bin;E:\PCL 1.8.1\bin;E:\PCL 1.8.1\3rdParty\OpenNI2\Tools;E:\PCL 1.8.1\3rdParty\VTK\bin;E:\python\Scripts\;E:\python\;C:\Users\sunmeina\AppData\Local\Microsoft\WindowsApps;E:\PCL 1.8.1\bin;C:\Users\sunmeina\AppData\Local\BypassRuntm;E:\cmake\bin;E:\python\lib\site-packages\numpy\.libs;E:\Las\LAStools\bin;

f = File("E:/dataTes/1001140020191217_las2laz.laz", mode='r')

# 查看點云的點格式及字段名稱

print('\nPoint Of Data Format: ', f.header.data_format_id)

print("\tExamining Point Format: ", end=" ")

for spec in f.point_format:

print(spec.name, end=", ")

print('\noffset: ', f.header.offset) # 偏移量

print('scale: ', f.header.scale) # 比例因子

print('min: ', f.header.min) # x、y、z 的最小值

print('max: ', f.header.max) # x、y、z 的最大值

print('file_signature: ', f.header.file_signature) # 文件標識

print('Point Of Data Format: ', f.header.data_format_id) # 點格式

print('data_record_length: ', f.header.data_record_length) # 點個數

print('FileCreateDay+Year: ', f.header.date)

print()

print('f.x: ', f.x)

print('f.y: ', f.y)

print('f.z: ', f.z)

print('f.intensity: ', f.intensity)

print('f.gps_time: ', f.gps_time)

print('f.raw_classification: ', f.raw_classification)

print()

f.close()

if __name__ == "__main__":

main()

4. pylas讀取.laz

import pylas

def lazread(path):

print('\n\n------------\n\n')

laz = pylas.read(path)

print(laz)

print(laz.header)

print(laz.point_format)

print(laz.header.version)

print(laz.point_format.id)

print(laz.header.file_signature)

print('offset: ', laz.header.offset_to_point_data)

print('version_major: ', laz.header.version_major)

print('version_minor: ', laz.header.version_minor)

print('point_count: ', laz.header.point_count)

print('legacy_point_count: ', laz.header.legacy_point_count)

print('file_source_id: ', laz.header.file_source_id)

print('global_encoding: ', laz.header.global_encoding)

print('date: ', laz.header.date)

print('data_record_length: ', laz.points_data.point_size)

print('point_size: ', laz.header.point_size)

print('point_data_record_length: ', laz.header.point_data_record_length)

print('uuid: ', laz.header.uuid)

print('are_points_compressed: ', laz.header.are_points_compressed)

print('offset: ', laz.header.offsets)

print('scale: ', laz.header.scales)

print('min: ', laz.header.mins)

print('max: ', laz.header.maxs)

print('-------\n')

print(laz.point_format.dimension_names)

print('laz.x: ', laz.x)

print('laz.y: ', laz.y)

print('laz.z: ', laz.z)

print('laz.intensity: ', laz.intensity)

print('laz.gps_time: ', laz.gps_time)

print('laz.points: ', laz.points)

print('laz.points_data: ', laz.points_data)

print(laz.points_data.point_format.id)

print(laz.points_data.array)

print(laz.points_data.point_size)

def main():

lazread('E:/Las/1001217_las2laz.laz')

print('-------------endl-----------')

if __name__ == "__main__":

main()

以上測試均在windows10中進行,都ok

centos服務器上 方式2中讀取laz方式的可以支持;方式3中的不支持,報錯如下:

raise ValueError(“Unable to read compressed file!”) ValueError: Unable to read compressed file!

總結

以上是生活随笔為你收集整理的python读文件en_python 点云las、laz文件的读取、写入、压缩的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。