您的位置:首页 > 编程语言 > PHP开发

基于Rasterio与matplotlib的DEM三维展示

2017-06-04 16:55 363 查看
直接上代码了

>>> from mpl_toolkits.mplot3d import Axes3D
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> import rasterio as rio
>>> f=rio.open(r'C:\Users\suns\Desktop\Ex1\dem')
>>> nrows=f.height
>>> nrows
327
>>> ncols=f.width
>>> Xmin=f.bounds.left
>>> Xmin
442189.26993154
>>> Xmax=f.bounds.right
>>> Xmax
444619.26993154
>>> Ymin=f.bounds.bottom
>>> Ymin
4161425.3140877
>>> Ymax=f.bounds.top
>>> Ymax
4163060.3140877
>>> x = np.linspace(Xmin,Xmax, ncols)
>>> y = np.linspace(Ymin,Ymax, nrows)
>>> X,Y = np.meshgrid(x, y)
>>> Z=f.read(1)
>>> print(Z)
[[ 1018.3137207 1021.53942871 1025.41796875 ..., 1079.36437988
1077.99060059 1075.89050293]
[ 1019.75012207 1023.7064209 1027.79187012 ..., 1082.44714355
1079.32910156 1077.33557129]
[ 1021.66424561 1025.62988281 1029.59558105 ..., 1085.37890625
1081.47424316 1079.17553711]
...,
[ 995.26403809 994.10968018 992.90063477 ..., 1112.69433594
1113.80249023 1114.9107666 ]
[ 999.4006958 998.52185059 997.52252197 ..., 1114.14465332
1115.0213623 1116.12963867]
[ 1003.53076172 1002.79931641 1001.77233887 ..., 1115.82263184
1116.56359863 1117.34851074]]

>>> region = np.s_[10:400,10:400]
>>> X, Y, Z = X[region], Y[region],Z[region]
>>> fig = plt.figure()
>>> ax = Axes3D(fig)
>>> ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='rainbow')
<mpl_toolkits.mplot3d.art3d.Poly3DCollection object at 0x0000000004F88940>
>>> plt.show()
>>>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: