问题描述
我有一组3D坐标点:[纬度,经度,高程]([X,Y,Z]),是从LIDAR数据得出的.这些点没有排序,并且这些点之间的步长或多或少是随机的.
I have a set of 3D coordinates points: [lat,long,elevation] ([X,Y,Z]), derived from LIDAR data.The points are not sorted and the steps size between the points is more or less random.
我的目标是构建一个函数,将这组点转换为具有恒定像素数的2D numpy矩阵,其中每个(X,Y)单元格都保留Z值,然后将其绘制为高程热图.
My goal is to build a function that converts this set of points to a 2D numpy matrix of a constant number of pixels where each (X,Y) cell hold the Z value, then plot it as elevations heatmap.
- 比例尺必须保持现实,X和Y应该具有相同的步长.
- 矩阵不必捕获精确的高程图像,显然,为了使像素数恒定,需要降低某种分辨率.
我想到的解决方案是为每个像素构建一个存储桶,遍历所有点,然后根据其(X,Y)值将其放入存储桶中.最后,创建一个矩阵,其中每个卖出均在相应的存储区中保存Z值的平均值.
The solution I was thinking of is to build a bucket for each pixel, iterate over the points and put each in a bucket according to it's (X,Y) values. At last create a matrix where each sell holds the mean of the Z values in the corresponding bucket.
- 由于我在这一领域没有太多经验,所以我很想听听一些技巧,特别是如果有更好的方法来解决此任务.
- 是否有一个numpy函数将我的点集转换为所需的矩阵? (也许是网格网格具有恒定值的步长?)
-
如果我构建的矩阵非常稀疏,步长为
- Since I don't have lots of experience in this field I would love to hear some tips and specially if there are better ways to address this task.
- Is there a numpy function for converting my set of points to the desired matrix? (maybe meshgrid with steps of a constant value?)
If I build very sparse matrix, where the step size is
min [min {Xi,Xj},min {Yk,Yl}]
min[min{Xi,Xj} , min{Yk,Yl}] for all i,j,k,l
有没有一种方法可以降低"分辨率并将其转换为具有所需大小的矩阵?
is there a way to "reduce" the resolution and convert it to a matrix with the required size?
谢谢!
推荐答案
您不需要重新发明自行车.
You don't need to reinvent the bicycle.
from matplotlib.mlab import griddata
import numpy as np
#-- Your coordinates
x = np.random.random(100)
y = np.random.random(100)
z = np.random.random(100)*10
#--
#-- Your new grid
xsteps=200 # resolution in x
ysteps=200 # resolution in y
xi = linspace(min(x), max(x), xsteps)
yi = linspace(min(y), max(y), ysteps)
Z = griddata(x, y, z, xi, yi) # interpolates between points in your data
#--
plt.pcolormesh(xi, yi, Z, cmap=plt.cm.hot) # plot your elevation map :D
plt.show()
这篇关于将坐标向量转换为numpy二维矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!