python矩阵变成向量_将坐标向量转换为numpy二维矩阵

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.

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.

scales must remain realistic, X and Y should have same step size.

the matrix doesn't have to catch the exact elevations picture, It will obviously need some kind of resolution reduction in order to have a constant number of pixels.

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.

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}] for all i,j,k,l

is there a way to "reduce" the resolution and convert it to a matrix with the required size?

Thanks!

解决方案

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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值