3D mapping and bathymetry styling with QGIS 2.18

This is a guest blog from Liam Mason, a spatial analyst with Marine Scotland.  Some of his other data visualisations can be seen on his @marinemaps Twitter account or the Marine Scotland Maps portal maps.marine.gov.scot

[Edit: the tutorial was modified to use the GDAL-based DEM (Terrain Analysis) tools instead of Raster Terrain Analysis]

I love mapping bathymetric data in 3D. It’s almost magical, the ability to draw back the veil of the sea and reveal the mysterious landscapes below.

Yet, it’s remarkably simple to do using QGIS 2.8 or higher.

3D bathymetry map of inner Firth of Forth.
Bathymetry of inner Forth made using QGIS 2.8 and qgis2threejs

The Plugins

This tutorial uses one core and two additional plugins, which can be installed using Plugins > Manage and Install Plugins…

Screenshot of showing Plugins option in menu 

Firstly, ensure that GdalTools is installed and activated.

Screenshot of QGIS showing GDAL tools

Secondly, search for qgis2threejs, and install.

Screenshot of QGIS plugins showing qgis2threejs

Thirdly, search for and install quickmapservices which will give you access to a variety of basemaps.

Screenshot of QGIS plugins showing QuickMapServices

Both of the latter plugins are available in the Web menu.

Lastly, you can further expand the basemaps available in QuickMapServices via Web > QuickMapServices > Settings > More services > Get contributed pack

Screenshot of QuickMapServices 'get contributed pack' option

Other software

This tutorial involves picking colours from the basemap.

The Windows version of QGIS has an  integrated color picker tool, but for those of you using Mac OSX, Just Color Picker is an alternative (and free) colour picker tool available on the App store.

Just Color Picker on App store
Just Color Picker on App store

The data

We’ll need a digital elevation model (DEM) which contains both bathymetric and terrestrial elevation data otherwise either the land or sea will be flat.

This tutorial uses the GEBCO 2014 gridded data:


Although the data is quite coarse at 30 arcseconds resolution, it’s suitable for 3D mapping at country-wide scale.

On GEBCO website, holding down the Shift key, click the left mouse button and drag to select the area for download.Screenshot of GEBCO website showing selection map

Click to expand GEBCO_2014 Grid (30 arc-second interval). Tick INT16 GeoTIFF (data)

Screenshot of GEBCO website

Scroll down and click  Add data to basket.  When the text on this button greys out, click View basket.

On the next site, select Check out your request.

Screenshot of BODC website

If you don’t already have an account with BODC, you’ll need to register. Don’t worry though, it’s free and you won’t get spammed with emails.

Once registered, log in using your email and password.  If you don’t want to supply a reason or funding information, simply type any character eg a space and Login to proceed.

Screenshot of BODC website

Once logged in, you can Download the data.

Screenshot of BODC website

Alternatively if you only want to map the undersea terrain, EMODnet (http://www.emodnet-bathymetry.eu/data-products) is a fantastic source of open bathymetry data, but you may need to merge the rasters.

(For the Firth of Forth image, I combined a licensed bathymetry product from OceanWise, with Ordnance Survey’s Panorama terrestrial product)

The method

Loading and configuration

Firstly, use the Add raster button to load the GEBCO DEM.Add Raster data button

Now we’ll drape a basemap imagery layer via QuickMapServices > ArcGIS Online > ArcGIS Online Imagery (options may vary depending on version of Contributed Pack)

[I had to use ESRI > ESRI Satellite. Ed.]

Screenshot of ArcGIS online imagery in QuickMapServices menu

Set the Project Properties to EPSG:3857. (Pseudo/Spherical/Web Mercator, whatever you want to call it!)

Screenshot of QGIS project properties in menu

Screenshot of project properties showing EPSG 3857 selected

This changes the project’s units to metres, which makes it easier to use the 3D plugin.

EPSG:3857 is the native projection for the basemap.  Other metre-based projections can be used to reduce distortion, but  other projections  may reduce performance if transforming / projecting on-the-fly.

Creating the 3D viewer

Zoom and pan to the area of interest.

Screenshot of ESRI world imagery

Load the qgis2threejs 3D plugin via Web > Qgis2threejs > Qgis2threejs

Screenshot of qgis2threejs in menu

Change the template file to 3Dviewer.html (this reduces some of the tools in the resulting interactive map)

Screenshot of template file in qgis2threejs

In World settings, enter an appropriate vertical exaggeration.  In this tutorial, we want to exaggerate large undersea features, so we’ll use 40, but normally we’d use a smaller value.

Screenshot of vertical exaggeration settings in qgis2threejs

(Note: if the project’s horizontal units are degrees, we’d need to use very small decimal values. That’s why we changed the project’s properties)

In DEM settings, ensure the GEBCO data is selected as the DEM Layer.

For the highest resolution output, slide the Resampling slider to the right and set the Resolution to 400% (these settings may need to adjusted depending on your computer’s performance).

Optionally, untick Build sides.

Screenshot of qgis2threejs DEM settings

Finally, set an Output HTML file path and Run to start

Screenshot of qgis2threejs file path and run options

It’ll take a moment to process, but the output HTML should load in your browser automatically. (In Internet Explorer 11, you may need to okay an error pop-up)

3D model of North Atlantic

Voila! You have an interactive 3D model of the north Atlantic. Neat, huh?

Improving the bathymetry style (colours)

The imagery basemap in this tutorial includes bathymetric shading at smaller scales.  We have more control if we create our own custom bathymetry style though. (The same tricks can be applied with for 2D mapping too)

Firstly, add another copy of the DEM using Add raster button, ensuring it’s positioned above the basemap in the table of contents.Add raster button

Right-click the copy layer and select Properties

Screenshot of layer properties in menu

In Style, select Singleband pseudocolor  as Render Type.

Set the Max to 0 and the Min to approximately the deepest point in the visible extent. We’ll use -2000 as an example.

Screenshot of raster style properties

Use the Add values manually button, double click on the value field for the resulting entry and enter -20.

Using a colour dropper tool, change the three colours to the lightest sea colour on the basemap. (If using high resolution aerial imagery, try to avoid sandy beaches)

Screenshot of raster classification values

Screenshot of colour options

Now adjust the colour for the deepest value (-2000 in example) by moving the V slider (value) to the left which will darken the colour. 

Screenshot of colour options

For the shallowest depth (0), adjust the opacity to 0%. Values shallower than 20m now fade to transparent.

Screenshot of colour options

We now have a bathymetry colour scheme that works stylistically with the basemap.

We can experiment by changing the depth values. The shallower depth works best between -10 and -30.  Changing the deeper value from -2000 to -1000 for example, the darker colour moves shallower.

Screenshot of ESRI World Imagery with custom bathymetry colours (no shading or texture)

Improving the bathymetry style (shading and texture)

Next we’ll improve the shading and texture.

Select Raster > Analysis > DEM (Terrain Models)…

Screenshot showing DEM tools

Select DEM as Input file

Set an output file.

Ensure mode is Hillshade.

The example data stores height data in metres but uses degrees as horizontal units, so the Scale should be 111120.  (See gdaldem guidance )

Tick Load into canvas when finished

Run tool using OK

Screenshot of DEM tools

When the hillshade layer loads, open the properties.  Experiment with the Style settings for different effects.

I tend to pick Soft light for blending mode, with increased brightness and increased contrast.

The default min and max values are rarely suitable, I used 125 and 255 respectively.  (HT to Ireland QGIS User Group)  

Screenshot of raster layer properties

The final improvement is to add a slope analysis via Raster > Analysis > DEM (Terrain Models)…

Screenshot showing DEM tools

Similar prodecure to hillshade, but select Slope for Mode.

Again, Scale should be 111120 for tutorial data. Same guidance applies for slope as per hillshade

Screenshot of DEM tools

Once loaded, adjust the Style Properties of the slope layer so Color gradient is White to black.

Like the hillshade analysis, experiment with Min/Max, blending modes, brightness, contrast, and transparency.

Screenshot of properties

Screenshot of transparency

The settings  in screentshots above are used in the example below.

ESRI World Imagery with custom bathymetry applied

We now have a custom bathymetry style with improved shading and texture. 

Finally, repeat the QGIS2threejs steps to create a 3D model using our custom bathymetric style.

3D model of North Atlantic using ESRI World Imagery and custom bathymetry

Ta-da!  Now have some fun and experiment with different basemaps!  

3D model of North Atlantic using OSM Mapnik and custom bathymetry
3D map using OSM Mapnik render