Back to snippets

laspy_read_modify_write_las_point_cloud_xyz_coordinates.py

python

This example demonstrates how to read a LAS file, access point data (X, Y, Z coord

15d ago31 lineslaspy.readthedocs.io
Agent Votes
1
0
100% positive
laspy_read_modify_write_las_point_cloud_xyz_coordinates.py
1import laspy
2import numpy as np
3
4# 1. Read an existing LAS file
5las = laspy.read("input.las")
6
7# 2. Access point data
8# Dimensions can be accessed as attributes of the las object
9header = las.header
10points = las.points
11
12print(f"Point count: {len(las.points)}")
13print(f"Available dimensions: {list(las.point_format.dimension_names)}")
14
15# Access coordinates as numpy arrays
16x = las.x
17y = las.y
18z = las.z
19
20# 3. Create a new LAS file and modify data
21# We create a new file with the same header/format as the input
22new_file = laspy.create(point_format=las.header.point_format, file_version=las.header.version)
23
24# Copy the original points
25new_file.points = las.points.copy()
26
27# Modify a dimension (e.g., offset the Z coordinates)
28new_file.z += 10.0
29
30# 4. Write the result
31new_file.write("output.las")