Mapping English councils

Until she moved on to better things, we used to beg favours from a friendly LG-Group GIS person to make maps for us (Zoe – you are missed). In theory, we still have arcview licenses somewhere but after at least two office moves and numerous changes in staff I don’t have the appetite to wrestle with the corporate IT people and get it re-installed and connected.

I decided to use open source software (QGIS), together with the newly opened Ordnance Survey data, to quickly hack together a few maps that use my local data as an attribute. The documentation I could find was either a bit worthy and slow, or expert and quick. If you half-know what you’re doing, and have a project in mind, these notes may help you make a map inside a day. 

In summary, this is what needs to happen:

  1. Get QGis (and some libraries)
  2. Get data from Ordnance Survey
  3. Simply the OS data so we don’t go out of our brains waiting all the time
  4. Export the attributes of the OS data, so we can separately add factoids about councils. I’ll be using plan status and facts about whether we’ve worked with them.
  5. Import the extended table, and join it to the original
  6. Ask the map to reflect the factoids – perhaps by using different colours or whether to display a council at all (the OS data includes Scotland and Wales which have different planning systems)

1. Get QGIS and some libraries

This will depend on what (and whose) machine you’re using. I’m using my ‘secret squirrel’ laptop that corporate people don’t know exists, running ubuntu and connected via the guest wi-fi to the outside world. If you’re using windows, see the all-in installer details and skip to section 2.

For some reason, the version of qgis in the stock software centre is very old. So, as per the instructions on the ‘download‘ page:

# using ‘update manager’ select settings > other software > ‘add’
deb http://qgis.org/debian oneiric main

sudo apt-get update
sudo apt-get install qgis

# note it installs python and GRASS support as standard, but I still required

sudo apt-get install python-gis

2. Get data from ordnance survey

http://www.ordnancesurvey.co.uk/oswebsite/products/boundary-line/index.html

We want two products,

  • the boundary line data ™ which is vector information of each local authority (and much else besides);  and
  • miniscale ™ which allows us to place the shapes of councils onto a meaninful map (with rivers, coastline etc)

You need to order them to receive a download link via mail (but so far no spam). You’ll end up with two files, minisc_gb.zip and bdline_gb.zip

I’ve unzipped everything into my file ../downloads/data (you’ll need to change your path as appropriate if following)

To begin, launch qgis and start a new project. To set up the mapping references are understood, open ‘project properties’ and click the CRS tab. Check the ‘on the fly’ transformation and change the coordinate reference system to OSGB 1936.

Let’s show a map. Use ‘open layer’ and find district_borough_unitary_region.shp

If your machine is anything like mine (a loyal but underpowered laptop) it will top out for 5 minutes while it struggles with the 60 Mb file. This happens every time we render. No one can work like this – let’s lose some resolution. [tip – if you want to play with the settings in the next step you will want to uncheck the “Render” checkbox at the bottom of the screen]

3. Simplify the data

Make sure your layer is selected on the left-hand side of the screen and (using the menus) go Vector > Geoprocessing tools > simplify geometry [if you can’t see this menu, recheck that you have python-gis installed properly]. It asks for a tolerance – I used 10% to shrink the 59Mb file down to 9Mb. To keep things clean (and to allow me to revisit this step if I was ultimately unhappy with the reduction in fiedlity) I saved this altered version as district_10_percent. Tidy up by removing the original layer.

The manual also suggests using a spatial index to speed things up (right click the layer > properties > general > create spatial index) but I didn’t notice much difference in my non-scientific comparison.

create spatial index

4. To export the existing attributes

To manipulate the attributes I used a library called mmqgis – follow the instructions to enable 3rd party repo’s and find and install the mmqgis plugin.

To export the attribute table it is as simple as using the plug-ins menu:

plug-ins > mmqgis > Attributes export to csv

You can then load the file you just exported in excel (or libre) and take a look. To prove the theory, I just made a test file by

  • deleting scotland (sorry)
  • deleting Wales (sorry)
  • removing all columns apart from NAME (just in case) and CODE (we’ll use this to reattach the table)

Then, I made a new column called “TEST” which had some numbers in it – I used a small range between 0 and 9 done at random. Just to see if I could link this field to some visible attribute.

English councils with nonsense test data

Save this as a csv file.

5. Import your local data and attach it

To import and display your local attributes on a map of England

plugins > mmqgis > Attributes join from CSV file

input file = your CSV

CSV field = CODE (it will default to NAME, which will work, but let’s be strict and use code)

join layer = districts_10_percent (see above)

join field = CODE

Satisfy yourself that England has reappeared by selecting only the layer called ‘joined’. Now we want to use our test field to alter shadings. In the process of importing the attribute table, any numbers are imported as text.

plugins > mmqgis > Text to float

Select your ‘joined’ table and the field ‘test’. Convert. Your text ‘1’ is now a floating point ‘1.0’.

6. Using a map to display attributes

The lovely mmqgis plugin makes this very easy:

Plugins > mmqgis > Color Map [sic]

Map layer = ‘numeric’

Band = ‘test’

Choose suitably vibrant presets

Ensure that your ‘numeric’ layer is the only one selected:

Check the numeric layer

And (if you’ve been able to resist the temptation thus far), check ‘Render’

A random variable, mapped.

Behold a thing of beauty. And all thanks to projects like qgis and mmqgis. And, less romantically, the broader availability of OS data. Now, let’s get mapping …

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s