laz格式点云数据读取并可视化为tif
import laspy
import numpy as np
import open3d as o3d
import rasterio
import laspy
laz_file = laspy.read("xx.las")
points = np.vstack((laz_file.x, laz_file.y, laz_file.z)).transpose()
x_min, y_min, z_min = np.min(points, axis=0)
x_max, y_max, z_max = np.max(points, axis=0)
resolution = 1.0 # 栅格分辨率,可以根据需求调整
width = int((x_max - x_min) / resolution)
height = int((y_max - y_min) / resolution)
grid = np.zeros((height, width), dtype=np.float32)
for point in points:
x, y, z = point
i = int((y - y_min) / resolution)
j = int((x - x_min) / resolution)
if 0 <= i < height and 0 <= j < width:
grid[i, j] = z
with rasterio.open(
'output.tif',
'w',
driver='GTiff',
height=grid.shape[0],
width=grid.shape[1],
count=1,
dtype=grid.dtype,
crs='EPSG:4326', # 设置合适的坐标系,根据实际情况调整
transform=rasterio.Affine(resolution, 0, x_min, 0, -resolution, y_max)
) as dst:
dst.write(grid, 1)