2013-07-18 21 views
1

我想使用DEM文件使用matplotlib生成模擬的地形曲面。但我不知道如何將光柵座標地理參照到給定的CRS。我也不知道如何以適合在3D matplotlib繪圖中使用的格式表示地理參考柵格,例如作爲numpy數組。在3D matplotlib中顯示地理參考的DEM曲面

這是到目前爲止我Python代碼:

import osgeo.gdal 

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

gt = dataset.GetGeoTransform() 
+0

爲什麼你需要你的地理參考DEM? – ala

+0

我需要在3D matplotlib中生成一個曲面,使得Z分量是DEM中給出的高度,而X和Y分量是DEM的東向和北向。 – EricVonB

回答

2

您可以使用正常的plot_surface方法從matplotlib。因爲它需要一個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) 

enter image description here