Skip to content

Instantly share code, notes, and snippets.

@hugoledoux
Last active January 25, 2024 13:25
Show Gist options
  • Save hugoledoux/1e66c85e84ca2820e7ce93c5b2d4a882 to your computer and use it in GitHub Desktop.
Save hugoledoux/1e66c85e84ca2820e7ce93c5b2d4a882 to your computer and use it in GitHub Desktop.
laspy filter
import laspy
import numpy as np
import sys
las = laspy.read('/Users/hugo/teaching/hw04-marking/data/area_full.laz')
#-- fetch all points within 100m of the median xyz of the file
coords = np.vstack((las.x, las.y, las.z)).transpose()
median = np.median(coords, axis=0)
distances = np.sqrt(np.sum((coords - median) ** 2, axis=1))
mask1 = distances < 100
# mask = (las.x >= min_x) & (las.x <= max_x) & (las.y >= min_y) & (las.y <= max_y)
# return np.column_stack((las.x[mask], las.y[mask], las.z[mask]))
#-- create a new file
new_file = laspy.create(point_format=las.header.point_format, file_version=las.header.version)
new_file.points = las.points[mask1]
#-- filter to keep only the ground
new_file.points = new_file.points[new_file.classification == 2]
new_file.write("good_points.laz")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment