首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否有方法将las文件块转换为另一种las文件类型?

是否有方法将las文件块转换为另一种las文件类型?
EN

Stack Overflow用户
提问于 2022-07-18 22:27:50
回答 1查看 23关注 0票数 0

转换函数似乎只有在执行laspy.read()时才能工作。但是,块迭代器的全部要点是不需要一次读取完整的文件。这就是我认为laspy.convert()的一个例子将与块迭代器一起工作的方式。

代码语言:javascript
复制
            # READ IN FILE
            with laspy.open(scan.las_file, mode='r') as las_open:
                for chunk in las_open.chunk_iterator(1_000_000):
                   chunk = laspy.convert(chunk,file_version='1.2', point_format_id=2)

                    # WRITE TO FILE
                    file_path = os.path.join(path, filename)
                    header = laspy.LasHeader(point_format=2, version='1.2')
                    with laspy.open(source=facility_path, mode='w', header=header) as las_write:
                        las_write.write_points(chunk)

但是,它会引发此错误:

代码语言:javascript
复制
\lib\site-packages\laspy\lib.py", line 318, in convert
    header = copy.deepcopy(source_las.header)
\lib\site-packages\laspy\point\record.py", line 230, in __getattr__
    raise AttributeError("{} is not a valid dimension".format(item)) from None
    AttributeError: header is not a valid dimension
EN

回答 1

Stack Overflow用户

发布于 2022-07-22 10:50:51

laspy.convert需要一个LasData类型的对象,而不仅仅是点,块迭代器返回一个ScaleAwarePointRecord

要实现使用块读/写的转换,您必须创建一个用作缓冲区的点记录,并使用copy_fields_from

示例:

代码语言:javascript
复制
with laspy.open(input_path, mode='r') as las_open:
    header = laspy.LasHeader(point_format=6, version='1.4')
    with laspy.open(output_path, header=header, mode="w") as las_write:

        buffer_chunk = laspy.PackedPointRecord.zeros(point_count=chunk_size, point_format=header.point_format)

        for input_chunk in las_open.chunk_iterator(chunk_size):
            output_chunk = buffer_chunk[:len(input_chunk)]
            output_chunk.copy_fields_from(input_chunk)
            las_write.write_points(output_chunk)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73029246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档