【问题标题】:Display a georeferenced DEM surface in 3D matplotlib在 3D matplotlib 中显示地理参考 DEM 表面
【发布时间】:2013-07-18 01:36:09
【问题描述】:

我想使用 DEM 文件使用 matplotlib 生成模拟地形表面。但我不知道如何将栅格坐标地理配准到给定的 CRS。我也不知道如何以适合在 3D matplotlib 图中使用的格式(例如作为 numpy 数组)来表达地理参考栅格。

到目前为止,这是我的 python 代码:

import osgeo.gdal

dataset = osgeo.gdal.Open("MergedDEM")

gt = dataset.GetGeoTransform()

【问题讨论】:

  • 为什么需要对 DEM 进行地理配准?
  • 我需要在 3D matplotlib 中生成一个表面,使得 Z 分量是 DEM 中给定的高度,X 和 Y 分量是 DEM 的东向和北向。

标签: python numpy matplotlib gdal osgeo


【解决方案1】:

您可以使用 matplotlib 中的普通 plot_surface 方法。因为它需要一个 X 和 Y 数组,所以它已经用正确的坐标绘制了。我总是觉得很难做出好看的 3D 图,所以视觉方面当然可以改进。 :)

import gdal
from mpl_toolkits.mplot3d import Axes3D

dem = gdal.Open('gmted_small.tif')
gt  = dem.GetGeoTransform()
dem = dem.ReadAsArray()

fig, ax = plt.subplots(figsize=(16,8), subplot_kw={'projection': '3d'})

xres = gt[1]
yres = gt[5]

X = np.arange(gt[0], gt[0] + dem.shape[1]*xres, xres)
Y = np.arange(gt[3], gt[3] + dem.shape[0]*yres, yres)

X, Y = np.meshgrid(X, Y)

surf = ax.plot_surface(X,Y,dem, rstride=1, cstride=1, cmap=plt.cm.RdYlBu_r, vmin=0, vmax=4000, linewidth=0, antialiased=True)

ax.set_zlim(0, 60000) # to make it stand out less
ax.view_init(60,-105)

fig.colorbar(surf, shrink=0.4, aspect=20)

【讨论】:

  • 代码在发布时似乎没有运行。 numpy 和 plt 的导入丢失并且数组 dims 不匹配
猜你喜欢
  • 2023-01-28
  • 2015-06-15
  • 2019-03-25
  • 1970-01-01
  • 2013-12-22
  • 1970-01-01
  • 2013-09-28
  • 1970-01-01
  • 2021-04-24
相关资源
最近更新 更多