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:

https://www.gebco.net/data_and_products/gridded_bathymetry_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

 

 

Adding web basemaps in QGIS 2.18

This is a very quick guide on adding web basemaps to QGIS 2.18.  I’ve created it as it is often the first step in creating a new map.

The easiest way to add in a basemap from the web is to use one of two plugins to add in the data for you. The two best plugins I have found for doing this are the OpenLayers and QuickMapServices.

OpenLayers:

The OpenLayers plugin from Sourcepole allows you to add in maps layers like OpenStreetMap (Including brilliant styles from Thunderforest and Stamen), Bing, Google and Apple.

The layers area accessed via the Web menu in the top bar of QGIS

The maps are called using their official Javascript API, making them very reliable. The only issue I have encountered is that the maps are slow to return; though I haven’t recently experienced the blank, un-returned tiles that used to blight this plugin in the past.

Use the drop down menus to choose a layer and then simply click on it to add it to your map.

QuickMapServices:

QuickMapServices from NextGIS has a huge number of services available (790 at the last count, but not all of them are active ) . You can select a few of these using the same select and click method as the OpenLayers plugin, but as there are so many to choose from the search interface is a much needed facility:

Once selected from the menu the Search QMS window opens on the right side of the map:

Once you have found a service you want, just click Add. There is a full cataloge on the NextGIS website here: https://qms.nextgis.com/

Along with the regular Web Mapping Services (WMS) you can also get Tile Map Services (TMS), Web Feature Services (WFS) and GeoJSON data piped straight into your map.

I have found layers added via QMS to be much quicker than those added using OpenLayers, however some layers are a little less stable and sometimes all layers from the plugin refuse to work without restarting QGIS.

Verdict:

OpenLayers is steady and stable and can usually be relied upon to provide you with maps. QMS has a much larger range of maps available and serves them up lightning fast, great for backdrop maps when making animated maps with the TimeManager plugin.

Basically, have them both installed and use whichever suits your project!