user10827304
user10827304

Reputation: 21

Split point cloud into cells of specific size in Python

I need to split point cloud into specific cell size in order to find Z min and Z max in that cell. I converted point cloud into array and create meshgrid but I don't know how to split point cloud/array to extend defined by meshgrid. Suggestion? Or is there some more appropriate approach?

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')

Thanks in advance

Upvotes: 2

Views: 2456

Answers (1)

David de la Iglesia
David de la Iglesia

Reputation: 2534

Using 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")

You can learn more about VoxelGrid here:

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

z_min is not currently supported but it should be easy to implement (contributions are wellcome ^^) following as reference:

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

Which is used in:

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

Upvotes: 1

Related Questions