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

 

 

Creating a statistical dot density map with QGIS

Dot Density maps:

These maps display the density and distribution of a phenomena over a geographic area. The markers, usually a dot or cross, represent the occurrence or an aggregation of occurrences which are then randomly distributed across distinct regions of the map. Colours can be used to represent different classifications to add an extra dimension to the map.

The example above shows votes to remain (red) and leave (blue) the European Union in the London Boroughs. Each dot represents 100 votes and these have been randomly scattered within each borough to represent the density of votes.

The Data

For this exercise we are going to use a geopackage which contains the outlines of the London Boroughs.  The attributes of the boroughs include the number of votes to remain and the votes to leave the EU. You can download the data here:

London Boroughs EU Referendum Results

Contains OS data © Crown copyright and database right (2017)

The Method

Field Calculator

Before we can start generating the dots on the map we need to create a column with a reduced number, as there were too many votes cast to give each one its own dot. To do this we will use the field calculator to create new attribute columns with the numbers of votes each way divided by 100.

  • Right-Click on LondonBoroughEURef in the table of contents and select Open Attribute Table
  • Click on the Open Field Calculator button above the table: 
  • You will need to set up the Field Calculator as follows:

  1. Make sure the Create a new field option is selected and enter the name 100 Leave Votes.
  2. Make sure the Output field type is set to Whole number (interger) and the Output field length can be left at the default 10.
  3. The expression needs to be: “Vote_Leave” / 100 you can user the Fields and Values section to the right to make sure you get the right field names and quote marks, just double click on the field name you want.
  4. Click OK.

Now repeat this process to create a similar column for the remain votes, call the column 100 Remain Votes. The table should now look like this:

Click Save edits  then toggle out of Edit mode 

Random points

 

Now we have the reduced quantities we can use QGIS to randomly assign points across each area.

Select the Random points inside polygons (variable) from the Vector > Research Tools menu.

Fill in the values as follows:

  1. Although we are making a density map we are going to use the Points count Sampling strategy.  This will assign the number of points in the Number field to each polygon.
  2. Choose 100 Leave Votes to be the Number field. Don’t choose Votes_Leave or Votes as you will then be creating a huge number of points in each polygon!
  3. Set a Minimum distance of 1 – 10 (map units, metres in this example) It is good to not have the points overlapping but not essential as we will mitigate this at a later stage. If you set this too high there may not be room for all the dots in the smaller boroughs.
  4. Save your file as a new Geopackage (or shapefile if you want to). These files will be quite big so it is best not to create a temporary layer.
  5. Click Run.  It will take a while as the algorithm has to cycle through the 33 boroughs.

Once the process has finished you will have points all over the map within the boundaries of the London Boroughs.  However the new layer added will be called Random Points in the layers panel.  We will need to change this before we create a similar file for the votes to remain.

  • Right-click on Random Points in the layers panel.
  • Click Rename and change the name to be 100 leave votes.

Now rerun the Random points inside polygons (variable) for the remain votes. Use the same process as above, but use 100 Remain Votes as the Number Value, call the new geopackage Remain Dots, and finally rename the layer in the layers panel to be 100 remain votes.

The map will now look something like this:

Styling the Map

As it stands this map is rather useless, the points are all overlapping and you can’t see the leave votes as the remain all lie over the top of them. Thankfully we can use the power of QGIS to style the points in a way that makes gives equal emphasis to dots from each layer.

First let’s style the London Borough polygons so that they don’t interfere with the dots.

  • Click on the LondonBoroughsEURef in the layers panel to highlight it and then press F7 on your keyboard to open the Live Style Dock on the right side of the map.
  • Click Simple Fill at the top of the Layer Styling panel.
  • Change the Fill to Transparent.
  • Change the Outline Width to be 0.6

The Outlines will now be clear but there will be no fill colour to interfere with the dots. We can now move on to styling the points.

We need to reduce the size of the points, so the map isn’t too crowded and give them a good colour. We also need to set a blend mode to account for any over lapping points.

  1. Use the drop down menu at the top of the Layer Styling panel to change the layer to 100 Remain Votes.
  2. Click Simple Marker to reveal more options.
  3. Set the Size to be 0.6 (Millimeters).
  4. Set the Outline Style to be No Pen.
  5. Set the Layer lending mode to be Multiply
  6. Set the Feature blending mode to be Multiply
  7. For Fill, click on the colour swatch.

We want to set this as red but we want to take down the saturation. This is to allow overlapping features to have a stronger colour; either a strong red where two features in the same layer are blended or a purple where there is overlap with the blue leave dots.

By picking colours of the same intensity we have also made sure that the map has minimal bias to one colour or the other. This is also maintained by the use of the Blend modes which mix into purple and so minimise the bias where one dot may have overlapped another of a different colour.

On the colour chart:

  1. Set R(ed) to be 255 (Full) and G(reen) and B(lue) to be 0.
  2. Go up to S(aturation) and bring this down to 70% making the red lighter. You will notice that the G and B values increase to 76.

The colour now has scope to increase its intensity if it overlaps with another dot.

Repeat the process above with the 100 leave votes layer except here we are going to use blue.  Just make sure you increase B(lue) to 255 rather than R(ed) when selecting the colour.

The map will now look like this, it works at  scales between 1:200,000 and 1:400,000.  You will need to have less dots if you want to zoom out further, or more or larger dots on a more zoomed in map.

Contains OS data © Crown copyright and database right (2017)

So you should now be able to make the distinction between the largely remain voting central London compared to the periphery where voting leave was more popular, particularly in the West.

Labelling

The final thing you can do to your map is add labels to the London Boroughs so you can tell which is which. With such a busy map we are going to need buffers round the text.

  1. On the Layer Styling panel, change to LondonBoroughEURef then switch to the Labels tab: 
  2. Change to show labels for this layer.
  3. Change Label with to NAME.
  4. Choose a weightier font, I have used Franklin Gothic Demi.

Next we need to work on the formatting of the text so click on the format tab:

 

 

 

  1. Enter a space in the Wrap on Character field.
  2. Change the Alignment to Center.

The labels will now be better placed over the boroughs, though there won’t be enough room for them all unless you are more zoomed in.

 

The final steps are to add a mask or buffer to the text to make it stand out over the dots.

Click on the Buffer tab to start making changes:  

  1. Click the cross to Draw text buffer.
  2. I have left the Size as 1, but you may want to change this depending on your font.
  3. Set the buffer’s Transparency to something like 33% to allow some colour to show through.

That is the end of the instructions, you should have a map that looks similar to the one below:

Contains OS data © Crown copyright and database right (2017)

Creating a Proportional Symbol map in QGIS 2.18

Creating proportional symbol maps in QGIS is made very easy in QGIS with two main methods for making them. You can use basic Single Symbol style with the  Size Assistant in the Data Defined Override,  or you can use the Graduated style and choose Size as the method of gradation. Below is a set of instructions on how to use either method to create proportional point symbols for your map.

The Data

  • Download the 1:10 million populated places (Simple) Shapefile from Natural Earth:
  • Add in the Stamen Toner Lite WMS using either the OpenLayers or QuickMapServices plugins. If you haven’t done that before, here is a quick guide:

Method 1: Graduated Symbols

This method works best when you want to use all the points in your dataset. QGIS allows you to vary the size of the data point based on the values in attributes of the data.

  • First, open the live layer styling menu by pressing F7.

Make sure the top menu is set to the Natural Earth Point data then change Single symbol to be Graduated.

There are now a few new options to play with:

  • Change Column to be pop_max
  • Change Method to Size
  • Change “Size from” to 3 and “to” to 20
  • Click the Classify button to see how this looks.

The map will automatically update to look like the map show below, zoomed in to the UK and Northwest France:

You have flexibility to change the number of classes and how you divide the classes, Equal Interval, Quantiles, Natural Breaks etc. You can also manually edit the classes by double click in the values column in the table.

Method 2: Data Defined Override

If you want a little more control over how the data is displayed this method allows you to quickly change maximum and minimum values without having to set each level in between.

  • First, open the live layer styling menu by pressing F7
  • Make sure the top menu is set to the Natural Earth Point data
  • Click on the Data Driven Override button  on Size

 

 

  • Click on the Size Assistant option at the bottom of the box.

You will now be looking at the Size Assistant dialog. The options here are very similar to using the method described above, allowing you to select the field to base the size on and having control over size of the points.

  • Set the Field to be POP_MAX
  • Set the Scale method to be Radius
  • Change the “Size from” to be 3 and “to” to be 20

As you can see in the example above the symbols automatically scale from the smallest to the largest values in the field selected. However where this method has a big advantage over the previous one you can set the upper limit to be different. The points will now automatically scale to this value without you having to manually update each range. This can be very useful if you are viewing only a portion of the data.

In the area we zoomed to in the previous method the largest cities are London and Paris, both having a population of below 10,000,000

  • Change the “Values from” to be 0 and “to10,000,000

You can now see int he map below there is a bigger range of point sizes than the previous method for the area of the map.

Blend Modes

A little added tip is to use the blend modes on your symbology, so you can see the basemap through the shapes and reveal the detail on any overlapping symbols:

  • In the Layer Rendering section of the style tab change the Layer blending mode to be Multiply. This will allow you to see the basemap through the points
  • Change the Feature blending mode to be Multiply. This will allow you to see overlapping points within the point dataset.

The Result: