Fancy shaded and scaled contour lines in QGIS

Daniel P. Huffman shared this gorgeous map earlier. ArcMap just got the functionality to create such contour lines.

CFnWnA5UkAAuFm9

Naturally I had to try to re-create that style in QGIS. I semi-succeeded:

You have a DEM, eg mtsthelens_after.zip. Generate a hillshade from DEM. Generate contour lines from DEM.
dem hillshade contours

Split the lines by segment, for example with the “Network” plugin. Select all features on your layer and then use its “Split” function.
Calculate the azimuth of each line. See this magical formula (I wish QGIS would have a function ready).
Rotate the angle according to your hillshade light angle. For example:
CASE
 WHEN ("azimuth"+270) > 360
  THEN ("azimuth"+270-360)/500
 ELSE ("azimuth"+270)/500
END

And use that to scale your lines’ widths (the 500 is a constant factor here to get them small enough).

Disable all layers but hillshade and contour lines.
Move hillshade above contour lines.
Set map background to black (equals 0 in the blending multiplication later).
Use black to white as color ramp for the hillshade.
Set hillshade’s blending mode to multiply.
You now have the bright parts of the contour lines. Unfortunately QGIS does not yet support blending modes for whole groups so you will have to combine this with the next step in a raster graphics tool of your choice. Gimp works fine.
Take a screenshot of something.

Invert hillshade color ramp to white to black.
Rotate your angle by 180 (so it would be 90 instead of 270 in the example above).
You now have the dark lines.
Take another screenshot.
conscalehilmul270 conscalehilmul90
Add both images to a image in Gimp, Color to Alpha with black, invert the dark one, choose nice background, done!

scaled line width

This is still pretty rough as it’s mostly hack after hack and not “done properly”™. The blending adds some shadows where there should not be. In a way the lines end up being same width because of this. The scaling was done arbitrarily, there is probably some smart way with a better scale. Some fancy smoothing of the lines would look great. Coloring the areas between the lines would probably improve it as well. Once QGIS gets support for blending modes of groups, this will be much easier.

2 thoughts on “Fancy shaded and scaled contour lines in QGIS

  1. Pingback: How to create illuminated contours, Tanaka-style | Free and Open Source GIS Ramblings

  2. Pingback: Another stab at creating a Tanaka-style contour map | Ecostudies

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.