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 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:
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:
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
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.
- Right-click on the London Borough EU Ref layer and select Open Attribute Table
- In the attribute table window click on the Field Calculator Button:
In the field calculator window we need to do the following:
- Check Create a new field
- Set the Output field name to be %_Remain
- Set the Output field type to be Decimal number (real)
- the Output field length can stay at 10 but set the Precision to be 2
- In the expression window create the following statement:
( “Vote_Remai” / “votes” ) * 100
- 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.
- Click on the Save Edits button:
- Click on the Edit Mode off button:
Styling the data
We can now apply a graduated colour scheme based on this new column.
- Press F7 on the keyboard to open the Layer Styling dock on the right side of the map
- Make sure you are editing the London Borough EU Ref layer at the top
- Change the Single Symbol option to Graduated
- Change the Column to %_Remain
- Change the Color ramp to RdBu (Red to Blue through White)
- Check the Invert option (this makes leave favouring areas blue and remain red, the standard colours adopted for the referendum results)
- Change the number of Classes to 7
- Set the Mode to be Equal Interval
- Click Classify
- 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:
- 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:
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:
- Set the style to be Single symbol, Simple fill
- Se the Fill to be Tranparent
- Set the Outline to be Black
- Increase the Outline width to 0.7 so it will show up a bit more clearly
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:
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:
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.
This can be left as the defaults.
The only thing to change here is to scroll down and switch off the Build Sides option.
This can be left as the defaults.
- First we need to set which polygon layer we are going to extrude up, check the box next to London Borough EU Votes.
- The main thing to change here is to set the Height value to be Votes
- 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.
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:
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.
Here is a link to the actual model created: