Created
January 26, 2024 10:00
-
-
Save hugoledoux/d6533bcbfc1c1ccc703fdfda73d9aa5f to your computer and use it in GitHub Desktop.
laspy create file + matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import laspy | |
import numpy as np | |
import sys | |
np.set_printoptions(precision=2, suppress=True) | |
# 0. Creating some dummy data | |
my_data_xx, my_data_yy = (np.random.random_sample(size=1000) * 100, np.random.random_sample(size=1000) * 100) | |
# print(my_data_xx) | |
my_data_zz = np.random.random_sample(size=1000) * 2 | |
my_data = np.hstack((my_data_xx.reshape((-1, 1)), my_data_yy.reshape((-1, 1)), my_data_zz.reshape((-1, 1)))) | |
# 1. Create a new header | |
header = laspy.LasHeader(point_format=8, version="1.4") | |
# header.add_extra_dim(laspy.ExtraBytesParams(name="random", type=np.int32)) | |
header.offsets = np.min(my_data, axis=0) | |
header.scales = np.array([0.1, 0.1, 0.1]) | |
# 2. Create a Las | |
las = laspy.LasData(header) | |
las.x = my_data[:, 0] | |
las.y = my_data[:, 1] | |
las.z = my_data[:, 2] | |
las.new_field = np.random.randint(-1503, 6546, len(las.points), np.int32) | |
las.intensity = np.random.randint(0, 500, len(las.points), np.int16) | |
#-- plot | |
import matplotlib.pyplot as plt | |
plt.plot(np.array(las.points.x), np.array(las.points.y), 'o') | |
plt.show() | |
las.write("new_file.laz") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment