利用matplotlib将dem数据绘制出来
from matplotlib import cbook
from matplotlib import cm
from matplotlib.colors import LightSource
import matplotlib.pyplot as plt
import numpy as np
from osgeo import gdal_array
# 读取dem文件
path = "C:\\......\\lms16_高程.tif"
# 将dem文件转为np.array数组
lmsdem = gdal_array.LoadFile(path)
nrows, ncols = lmsdem.shape
# 设置x轴坐标
x_array = np.zeros((nrows,ncols))
def xaxis(a,b):
for i in range(a,b):
x_array[i,:] = i
return x_array
x = xaxis(0,nrows)
# 设置y轴坐标
y_array = np.zeros((nrows,ncols))
def yaxis(a,b):
for i in range(a,b):
y_array[:,i] = i
return y_array
y = yaxis(0,ncols)
# 设置绘制区域的范围
region = np.s_[1300:1500,1150:1400]
x,y,z = x[region],y[region],lmsdem[region]
fig, ax = plt.subplots(subplot_kw = dict(projection='3d'))
ls = LightSource(270, 45)
rgb = ls.shade(z, cmap=cm.gist_earth, vert_exag=0.1, blend_mode='soft')
surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, facecolors=rgb,
linewidth=0, antialiased=False, shade=False)
plt.show()
效果展示
俯视效果
版权声明:本文为Corollary原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。