Creating 3D choropleth or prism map in QGIS 2.18

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

It is possible to very quickly render any choropleth map you make in QGIS in 3D using the Qgis2threejs plugin. Essentially the plugin allows you to turn a numerical attribute as a “height” for your data. The results from the plugin are outputted as an html page which can be easily shared in a folder or placed on the web for people to view.

The Data

Votes:

The Electoral Commission website contains a lot of data that can be used for making choropleth maps of all kinds. For this post I have used the EU Referendum results .CSV file:

https://www.electoralcommission.org.uk/__data/assets/file/0014/212135/EU-referendum-result-data.csv

Boundaries:

If you are making choropleth maps of Great Britain then the best place to start with when looking for boundaries is the Ordnance Survey’s Boundary-Line Data:

https://www.ordnancesurvey.co.uk/opendatadownload/products.html#BDLINE

The Method

I have used the data above to create a shapefile of London Boroughs with attributes that include the total number of votes, the number of votes to remain in the EU, and the number of votes to leave from the 2016 EU referendum. This was done using a table join based on the Area_Code from the result data CSV and the CODE in the Boundary-Line data for the London Boroughs.

The new file is called London Borough EU Ref and you can download a copy here: LondonBoroughEURef.zip

I have also added in a Stamen Toner (Retina) basemap using the method described here: Adding web Basemaps in QGIS 2.18

Adding Qgis2threejs

To start creating your Prism Map you will need to add in the Qgis2threejs plugin using the Manage and Install Plugins interface:

Once installed you access the plugin via the Web menu in the top bar:

Setting up the data

Before we can get to work creating a 3D map we need to set up the data in the 2D map. In this example we are going to show the number of votes in the referendum for the London Boroughs as the 3D height, however we have the option to use the colour of the boroughs to show a second attribute. It is actually very useful to make the polygons different colours as it is then easier to interpret the map.

  1. Right-click on the London Borough EU Ref layer and select Open Attribute Table
  2. In the attribute table window click on the Field Calculator Button:

In the field calculator window we need to do the following:

  1. Check Create a new field
  2. Set the Output field name to be %_Remain
  3. Set the Output field type to be Decimal number (real)
  4. the Output field length can stay at 10 but set the Precision to be 2
  5. In the expression window create the following statement:

    ( “Vote_Remai” / “votes” ) * 100

  6. Click OK

You will now see the new column in the attribute table but you still need to save your change and turn off editing mode.

  1. Click on the Save Edits button:
  2. Click on the Edit Mode off button:

Styling the data

We can now apply a graduated colour scheme based on this new column.

  1. Press F7 on the keyboard to open the Layer Styling dock on the right side of the map
  2. Make sure you are editing the London Borough EU Ref layer at the top
  3. Change the Single Symbol option to Graduated
  4. Change the Column to %_Remain
  5. Change the Color ramp to RdBu (Red to Blue through White)
  6. Check the Invert option (this makes leave favouring areas blue and remain red, the standard colours adopted for the referendum results)
  7. Change the number of Classes to 7
  8. Set the Mode to be Equal Interval
  9. Click Classify
  10. Manually adjust the Values to 10% bands, starting at 20% votes to remain through to 80% votes to remain. Make sure that white represents 50%. If you double click in the the value column of the table in the Layer Styling dock it will open a window where you can edit each entry:
  11. Finally change the Layer Blending Mode to Multiply so that you can see the details of the base map through the colours with no nasty washed out effect you get with transparency. This effect works particularly well on the black and white basemap.

The resulting map is shown below, with the areas of the lowest votes to remain as the darkest blue, white represents 50%, and the darkest red in the areas with the most votes to remain:

Map data © OpenStreetMap contributors, Contains OS data © Crown copyright and database right (2017)

The Prism maps produced by Qgis2threejs show a flat plane with extruded blocks extending upwards. The flat plane will appear as it is in the map window. It can be good to have a little transparency on the extruded blocks and so you don’t want the colours you have just set interfering with this. However it can be useful to see the boundaries you are extruding upwards. To show these:

  • Right-click on the London Borough layer
  • Select Duplicate

You will end up with a copy of the layer called London Borough EU Ref copy

Style the new layer to show just the outlines:

  1. Set the style to be Single symbol, Simple fill
  2. Se the Fill to be Tranparent
  3. Set the Outline to be Black
  4. Increase the Outline width to 0.7 so it will show up a bit more clearly
Contains OS data © Crown copyright and database right (2017)

Preparing the map for conversion to 3D

You should now turn off the coloured London Boroughs layer and use the Zoom to Layer Extent to set up the map as show below:

Map data © OpenStreetMap contributors, Contains OS data © Crown copyright and database right (2017)

Setting up Qgis2threejs

You can now open the Qgis2threejs plugin from the Web menu:

There are a a whole raft of options to look at with this plugin as it can be used not only for Prism Maps but for accurate 3D landscape models too.

We’ll run through the changes needed to make a Prism Map, the rest of the parameters can be left as the default settings.

Well start at the top of the menu on the left:

World

The only thing to change here is the Background colour. The default is sky which works well for landscapes but I have set this to black which works better for the colours of this map.

Controls

This can be left as the defaults.

DEM

The only thing to change here is to scroll down and switch off the Build Sides option.

Additional DEM

This can be left as the defaults.

Polygons

  1. First we need to set which polygon layer we are going to extrude up, check the box next to London Borough EU Votes.
  2. The main thing to change here is to set the Height value to be Votes
  3. multiplier to be 0.1. The values are set in map units but as there were so many votes this makes the Prisms too high. if you are dealing with low values over larger areas then you will need a high multiplier to see any effect.

The Results

So now you are ready to Run the plugin, I tend to leave the location to be the temp folder while I play around with the colours, zoom levels and height multipliers. Once you are happy then you can set your location and the plugin will create a folder there with all the information needed to create the html page:

Here is the result:

Map data © OpenStreetMap contributors, Contains OS data © Crown copyright and database right (2017)

Note that the website can take a while to generate and the more complicated the geometries of the polygons the longer it takes to render. Microsoft Edge and Internet Explorer can take a bit longer to display than FireFox and Chrome, but once loaded all browsers tend to run well.

One thing I have found is that the models look better when the polygons are simple. American States, which have a lot of straight lines, tend to work better than UK counties or constituencies. Here is the same data for London, but put into HexBins. I’ve added labels to help identify which hexagon represents which borough.

It is possible to edit the CSS to change things like the font and text size for the labels.

Map data © OpenStreetMap contributors

Here is a link to the actual model created:

London Remain Votes Prism Map