Skip to content

Instantly share code, notes, and snippets.

@lymperis-e
Last active August 17, 2022 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lymperis-e/04ff35792edf6e3155ea23f25ec922db to your computer and use it in GitHub Desktop.
Save lymperis-e/04ff35792edf6e3155ea23f25ec922db to your computer and use it in GitHub Desktop.

Creating a smooth Hillshade basemap in QGIS


While hillshading a DEM/DTM in QGIS is fairly straightforward, the result is often not what you want to use in a map. Fortunately, achieving a neat, smooth result is not so tough. My aim for this procedure was to create a visually pleasing hillshade for use as a base layer for other mapping products (somewhat like OpenTopoMap). We 're gonna need

  • QGIS 3.18 (any version >= 3.10)
  • SAGA 2.3.2
  • the amazing Terrain Shading plugin

Step 1

First, we need some data. I easily obtained the DEM for the area of Lasithi in Creta island, from OpenTopography

I used the web interface, but the easiest way to do it is to use the OpenTopography DEM Downloader plugin.

image image

Load it into QGIS and hillshade it using the default settings. Altough it is nice, there is much room for improvement (at least for our current purpose)

image

Step 2

Open the processing toolbox, and search for SAGA's Gaussian filter.

image

image

I found that for the SRTM product, the following parameters work nicely:

Std Dev Search Mode Search Radius
2.00 Circle 3

The Gaussian filter smooths the original data by transforming each pixel according to the value of a Gaussian function. You can read about the theory of Gaussian filtering here. In practice, it is one of the most common blurring/smoothing techniques.

We can easily demonstrate the visual implications of the filter by comparing the contour lines of the DEM before & after applying it. Note that while the visual result may be more appealing, topographic accuracy & precision will usually decrease.

Raw Filtered
image image

Step 3

Open the Hillshade tool form the Terrain Shading toolbox, and apply it to the filtered layer. I used Bidirectional hillshade, with the sun at 70 degrees, and a lateral exaggeration factor of 3. Also make sure to check Denoise for some extra denoising/smoothing. Depending of the topography of your area, you may want to increase the lateral exaggeration substantially. Later on I figured that for the area I chose, a factor of 5 worked even better

Note that you have to reproject the DEM to a metric system (one that uses meters instead of degrees). The plugin will warn you, and usually it will circumvent any problems, but in case it fails you know what to do!

image

Step 4

This is optional, but recommended in most cases. Apply the Gaussian Filter again to the Hillshade layer. This will smooth out any rough/square-ish areas. You can use the same settings as before (thought I like to to go with Std. Dev.: 2.00)

Step 5

This is where the magic happens. Set the transparency of the created hillshade layer to 35% (or adjust it to your liking), and apply a light colorisation. I like to go with light yellow tones, like #fff3bf

image

This type of hillshade particularly complements our contour lines

image

You can save this gist and load it to style your contours

image image

VHR Data

If you are using Very High Resolution elevation data (<5m), you might notice some linear artifacts in the rendering that QGIS performs.

image

These persist even when applying the Gaussian filter. One way to remove them, is to export our final hillshade, and select Output mode: Rendered image. This way QGIS propely renders the elevation model, and removes these artifacts. This is not the case if you keep the DEM as-is, and try to export a map via the Layout editor.

image

And....

image


The procedure we followed is illustrated below.

image

You can download this code and import it as a Processing Script to use it directly, and avoid the middle steps. Open the code editor window as demonstrated below, paste the code and run it. You can also save it, and always have it available in the processing toolbox.

image

Now finally, let's add a nice sea surface for contrast....And voila!

(NOTE: I know the sea surface intersects the contour....Yes, this should not happen. I was just too lazy to extract the sea surface from the DEM, of find a better source)

image

I hope this was useful, happy mapping !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment