繁体   English   中英

如何使用GDAL python从LiDAR点(X,Y,Z)创建网格?

[英]How to create a grid from LiDAR points (X,Y,Z) with GDAL python?

我真的是python编程的新手,我只是想知道您是否可以使用LiDAR点创建0.5 x 0.5 m分辨率的常规网格。

我的数据为LAS格式(从liblas导入文件读取为lasfile),并且具有以下格式:X,Y,Z。 其中X和Y是坐标。

这些点是随机放置的,并且某些像素为空(NAN值),并且在某些像素中有一个以上的点。 如果有更多一点,我希望获得一个平均值。 最后,我需要将数据保存为TIF格式或Ascii格式。

我正在研究osgeo模块和GDAL,但老实说,我不知道osgeo模块是否是最佳解决方案。

我很高兴为我可以学习和实现的一些代码提供帮助,

在此先感谢您的帮助,我真的很需要

我不知道获得带有这些参数的网格的最佳方法。

有点晚了,但也许这个答案对其他人有用,如果不是对您...

我已经用Numpy和Pandas完成了,而且速度很快。 我使用的是TLS数据,并且可以在一台像样的2009年老式笔记本电脑上毫无问题地处理数百万个数据点。 关键是通过对数据进行四舍五入进行“合并”,然后使用Pandas的GroupBy方法进行汇总并计算均值。

如果需要舍入为10的幂,可以使用np.round,否则可以通过使函数舍入为任意值,这是我通过修改此SO answer来完成的。

import numpy as np
import pandas as pd

# make rounding function:
def round_to_val(a, round_val):
    return np.round( np.array(a, dtype=float) / round_val) * round_val

# load data
data = np.load( 'shape of ndata, 3')
n_d = data.shape[0]

# round the data
d_round = np.empty( [n_d, 5] )
d_round[:,0] = data[:,0]
d_round[:,1] = data[:,1]
d_round[:,2] = data[:,2]

del data  # free up some RAM

d_round[:,3] = round_to_val( d_round[:,0], 0.5)
d_round[:,4] = round_to_val( d_round[:,1], 0.5)

# sorting data
ind = np.lexsort( (d_round[:,4], d_round[:,3]) )
d_sort = d_round[ind]

# making dataframes and grouping stuff
df_cols = ['x', 'y', 'z', 'x_round', 'y_round']
df = pd.DataFrame( d_sort)
df.columns = df_cols
df_round = df[['x_round', 'y_round', 'z']]
group_xy = df_round.groupby(['x_round', 'y_round'])

# calculating the mean, write to csv, which saves the file with:
# [x_round, y_round, z_mean] columns.  You can exit Python and then start up 
# later to clear memory if that's an issue.
group_mean = group_xy.mean()
group_mean.to_csv('your_binned_data.csv')

# Restarting...
import numpy as np
from scipy.interpolate import griddata

binned_data = np.loadtxt('your_binned_data.csv', skiprows=1, delimiter=',')
x_bins = binned_data[:,0]
y_bins = binned_data[:,1]
z_vals = binned_data[:,2]

pts = np.array( [x_bins, y_bins])
pts = pts.T

# make grid (with borders rounded to 0.5...)
xmax, xmin = 640000.5, 637000
ymax, ymin = 6070000.5, 6067000

grid_x, grid_y = np.mgrid[640000.5:637000:0.5, 6067000.5:6070000:0.5]

# interpolate onto grid
data_grid = griddata(pts, z_vals, (grid_x, grid_y), method='cubic')

# save to ascii
np.savetxt('data_grid.txt', data_grid)

完成此操作后,我将输出另存为.npy并通过图像库转换为tiff,然后在ArcMap中进行地理定位。 可能有一种方法可以用osgeo做到这一点,但我还没有使用过。

希望这至少可以帮助某人...

您可以使用Numpy中的直方图功能进行合并,例如:

import numpy as np
points = np.random.random(1000)
#create 10 bins from 0 to 1
bins = np.linspace(0, 1, 10)
means = (numpy.histogram(points, bins, weights=data)[0] /
             numpy.histogram(points, bins)[0])

尝试使用LAStools ,尤其是lasgridlas2dem

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM