Code covered by the BSD License  

Highlights from
DEM: Shaded relief image plot (digital elevation model)

4.9 | 12 ratings Rate this file 79 Downloads (last 30 days) File Size: 11.7 KB File ID: #36380 Version: 2.1
image thumbnail

DEM: Shaded relief image plot (digital elevation model)



25 Apr 2012 (Updated )

Pretty shaded relief map as flat image.

| Watch this File

File Information

This function plots regular grids of elevation X,Y,Z in a more efficient manner than SURFL Matlab's function, because it recomputes lighting and displays result as shaded color flat RGB image. It uses also median-style filter to deal with min/max values of elevations and gradient, and proposes two specific colormaps "landcolor" and "seacolor".
Color mapping and lighting parameters can be changed from default values. In addition, several options are available: 'cartesian' to add decimal axis, 'latlon' to add geographical axis (GMT-like), 'legend' for an automatic scaling legend, 'lake' for automatic flat area color-filling and 'interp' to fill the novalue gaps...
This may be useful to produce high-quality and moderate-size Postscript image adapted for publication. Also, the output image is not dependant on current figure colormap, thus additional plots with indexed colors can be added (contour, pcolor, ...).
Figure examples:

Moon North Pole using the bone colormap and high contrast lighting (DEM source: raster LRO/LOLA LTVT)

Indonesia archipelago using default colormaps, 'latlon' axis basemap and legend scales (DEM source: raster NOAA/NGDC ETOPO1)

Soufrière of Guadeloupe volcano lava dome: 1-m resolution with NaN values (DEM source: OVSG-IPGP/SCIAC)

See "doc dem" for syntax, examples and help. See also the READHGT function from same author.


This file inspired Shadem.

Required Products MATLAB
MATLAB release MATLAB 7.13 (R2011b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (19)
29 Oct 2015 Camilo Márquez

Hi François
Thank you for the code. Where i find the code of the pictures example's?

02 Sep 2015 cheng joylin  
18 Aug 2015 François Beauducel

Dear Tomke,
Thanks for the rating and the tip. But freezecolors uses CData to make RGB colors. So you won't be able to print vectorial PostScript from your figure:
>> print -depsc -painters freeze.eps
Warning: RGB color data not yet supported in Painter's mode
> In /Applications/>hardcopy at 36
In graphics/private/render at 109
In print>LocalPrint at 276
In print at 233
And you get a raster image... Same problem with all previous releases of Matlab. I have already written a similar solution in dem.m, but I am working on a new one compatible with the painters mode.

Comment only
17 Aug 2015 Tomke Froechtenicht

Hi, thanks for your quick reply. When you install the oackage "freezecolors" ( than you can plot contourplots over the elevation map.

My code:
dem (lon,lat,topo,...'legend');
[c,h]=contour(xkoord,ykoord,I,100); %Konturplot
colormap hot;
hc=colorbar('location','Eastoutside','Fontname','FixedWidth'); %Legende
'position', [pos(1)*1.1 pos(2)*0.9 pos(3)*0.5 pos(4)],'fontsize',8);
Cheers! Tomke

15 Aug 2015 François Beauducel

Dear Tomke,
This possible in principle: the image produced by dem.m is not indexed but RGB, so independant from colormap function. But I forgot to apply this transformation to the colorbar used by 'legend' option. I'll fix this in the next release. By now you can use a different colormap for contour, with colorbar, but without the elevation legend/colorbar.

Comment only
14 Aug 2015 Tomke Froechtenicht

how can I overlay the DEM-plot with a contourplot that has another colorbar/legend?

Comment only
25 Feb 2015 Melanie Bieli

Super beautiful, thanks a lot for sharing this!

24 Oct 2014 Matteo Niccoli  
14 Aug 2014 amrit

amrit (view profile)

13 Mar 2013 Fred Massin

This is great to be able (finally!) to export vector shaded image with matlab, thank you!

11 Jan 2013 Mathieu

Exactly what I was looking for. Great Job!

08 Jan 2013 Julia

Julia (view profile)


Looking forward to using this code. For those of us who mask our DEMs with NaNs, it would be great to have an option to set NaN to white instead of black.


02 Dec 2012 François Beauducel

Hi Carlo,
To add the colorbar you need to use the dem(...,'scale') option. Type doc dem to get all the available options.

Comment only
01 Dec 2012 Carlo M

thank you for the code
please, how can I add a colorbar?

Comment only
10 Sep 2012 Zhishan  
25 Jun 2012 sangram ganguly

This is a fantastic code - I love this as I do not have to use the surfl command and other mapping toolbox commands to generate my DEM and drape with other images. Thanks a ton !!
Guys - if you are dealing with 10m DEM with huge matrices, forget about mapping toolbox functions to do your draping - use this function - generate the DEM (use the matrices generated e.g. I in this case) and then use the geotiffwrite command to create beautiful tif images and do the rest in photoshop.

24 Jun 2012 François Beauducel

Dear Cristopher,
You must download the file, unzip into your Matlab directory, then type "doc dem" at Matlab prompt.
Or, you can clic on dem.m (on the right of the function window under "Highlights from..."): this will display the function's comments including the doc.

Comment only
24 Jun 2012 cristopher

Sorry, François:
I can't find the "doc dem" for sintax, examples and help.
Can you help me

Comment only
28 May 2012 Martin Richard  
26 Apr 2012 1.1

Optimizations: adds a decimation for large DEM grids.

14 May 2012 1.2

ZIP now contains landcolor.dat companion file.

18 May 2012 1.3

- new landcolor.m colormap function
- new arguments to control colormap scaling
- median-style filters for light and colormap

29 May 2012 1.4

- adds basemap-style axis in decimal or lat/lon modes
- adds elevation and distance scales

26 Sep 2012 1.5

now accepts row/column vectors for X and/or Y.

02 Jan 2013 1.6

- adds a 'lake' option
- minor bug correction

07 Jan 2013 1.7

- adds 'interp' option (fill the gaps)
- adds 'seacolor' colormap for negative elevations (bathymetry)

14 Jan 2013 1.8

- improved light rendering (using surface normals instead of gradient)
- improved 'lake' detection algorithm
- new 'nancolor' option to set NaN color
- adds a length scale with 'dec' option
- minor code improvements

11 Mar 2013 1.9

- new options: 'km', 'watermark', 'fontsize', 'bordersize'
- improve legend colorbar
- all options now passed as param/value

09 Sep 2014 1.10

improve backward compatibility (strjoijn)

19 Aug 2015 2.0

legend scale is now liberated from the figure colormap (thanks to Tomke Froechtenich's comment). No use of freezecolors needed to add other colormap plots.

22 Aug 2015 2.1

minor fix

Contact us