python - Display a georeferenced DEM surface in 3D matplotlib -
i want use dem file generate simulated terrain surface using matplotlib. not know how georeference raster coordinates given crs. nor know how express georeferenced raster in format suitable use in 3d matplotlib plot, example numpy array.
here python code far:
import osgeo.gdal dataset = osgeo.gdal.open("mergeddem") gt = dataset.getgeotransform()
you can use normal plot_surface
method matplotlib. because needs x , y array, plotted right coordinates. find hard make nice looking 3d plots, visual aspects can improved. :)
import gdal 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) # make stand out less ax.view_init(60,-105) fig.colorbar(surf, shrink=0.4, aspect=20)
Comments
Post a Comment