在Python中将点云拆分为特定大小的单元格

时间:2018-12-24 00:01:47

标签: python split point-clouds

我需要将点云拆分为特定的像元大小,以便在该像元中找到Z min和Z max。我将点云转换为数组并创建了meshgrid,但是我不知道如何将点云/数组拆分为由meshgrid定义的扩展。建议?还是有一些更合适的方法?

import laspy
import numpy as np
inf = laspy.file.File('SAVA_000012.las', mode='r')
points = inf.points
points_xyz = np.array((points['point']['X'],
                   points['point']['Y'],
                   points['point']['Z'])).transpose()
x = np.arange(min(inf.X), max(inf.X), 200)
y = np.arange(min(inf.Y), max(inf.Y), 200)
print(x)
xx, yy = np.meshgrid(x, y, sparse=True, indexing= 'xy')

预先感谢

1 个答案:

答案 0 :(得分:0)

使用https://github.com/daavoo/pyntcloud

from pyntcloud import PyntCloud

cloud = PyntCloud.from_file("SAVA_000012.las")

# Using 0.15 just for example. Omit `z` for 2D grid
voxelgrid_id = cloud.add_structure("voxelgrid", size_x=0.15, size_y=0.15)

voxelgrid = cloud.structures[voxelgrid_id]

z_max = voxelgrid.get_feature_vector(mode="z_max")

您可以在此处了解有关VoxelGrid的更多信息:

https://github.com/daavoo/pyntcloud/blob/master/examples/%5Bstructures%5D%20VoxelGrid.ipynb

z_min目前不受支持,但应该易于实现(贡献颇丰,^^),仅供参考:

https://github.com/daavoo/pyntcloud/blob/master/pyntcloud/utils/numba.py#L19

用于:

https://github.com/daavoo/pyntcloud/blob/master/pyntcloud/structures/voxelgrid.py#L161