I have DEM ( Digital Elevation Model ) data, and I want to perform a representation of it, in the form of heatmap or 3d surface.

I have the data converted from the .img DEM using gdal_translate in the following format in plain text csv of near 5000 lines :


I want to know how should I proceed to normalize the data ( if its neccesary ) and then represent it as heatmap and/or grid/surface interpolating it.

I do like this kind of representation:

enter image description here

enter image description here

Im a Python developer, and whilet Im not restricted to this language, matplotlib, pandas, and his friends are welcome for myself.

Even when I don't know this field I was trying using this code example from github to represent it and Im not sure if its the correct way to do it.

# Based on example from:
# https://github.com/kjordahl/SciPy2013/blob/master/examples/kauai.py

import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from osgeo import gdal

import Image


DEM = gdal.Open("dem.tif")

DEM_Array = DEM.ReadAsArray()

DEM_ArrayM = np.ma.masked_equal(DEM_Array,DEM_Array==0)

i, j = np.where(DEM_ArrayM>0)

topo = DEM_ArrayM[0:max(i)+1, 0:max(j)+1]

fig = plt.figure(frameon=True)

plt.imshow(topo, cmap=cm.gist_earth)


cbar = plt.colorbar(shrink=0.9)


plt.savefig('plot_name.png', dpi=300, bbox_inches='tight')

  • If R is useable for you read the original file (not the csv) with r <- raster::raster(file), then convert to mesh with qm <- quadmesh::quadmesh(r), then plot with library(rgl); shade3d(qm) – mdsumner Jun 27 '17 at 22:40
  • The easiest is probably to stick to the original raster format you had (.img), read the data directly as a numpy array (e.g. using rasterio), and plot the array with imshow or plot_surface – Loïc Dutrieux Jun 27 '17 at 23:11
  • Hi! Thanks for your reply. I like that way. Some questions about it. 1) Do you have any code examples to look at ? 2) Is it possible to plot the information already processed ? Because in some cases I do not have the original .img files. Thanks! – jrodriguezmonti Jun 28 '17 at 1:14
  • What you do with the data depends on how it should be presented / decimated. What are you trying to say about the terrain? – BradHards Jun 28 '17 at 9:24
  • I would like to colorize the elevation. Some colors the higher, some other colors the lower, and so on. I want to know how to treat the data before representing it. I want to do that, and represent it as surface and heatmap. Thanks! – jrodriguezmonti Jun 28 '17 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.