Thursday, 30 June 2022

Labelling tips and tricks for QGIS

It has been said that making a map is 80% labelling, and 20% everything else. Okay, I just made that up, but if you've spent any time at all using GIS software you'll see the truth in this. Sometimes I end up spending far too much time on labelling, but then again it's usually time well spent because it makes things clearer. Too many labels and we're overwhelmed, too few and we're left guessing. I put this post together for anyone who uses QGIS and wants to know a bit more about labelling - just some tips and tricks for general use, regardless of what QGIS version you're on. I'm going to do this on a Pacific-centric world map, because there aren't enough of them and it's nice to look at things from a non-Greenwich perspective. Here's a little example map below, and then everything is explained after that. I'm working on this kind of thing for my next Map Academy course on Udemy.

A little example, using data from simplemaps.com

The data

As you can see, I'm using a Pacific-centric world map layer. This is based on the Natural Earth land layer and I just clipped it at 30 degrees west so that when I projected it using the Sphere Equal Earth Asia Pacific CRS in QGIS it didn't go all weird with Greenland and Antarctica split across the meridian. But of course you don't need to do this if you want to follow along - you can just add any world map layer, or none at all, because this is about labelling places.

For the cities layer, you can get it at simplemaps.com as a csv and then load it into QGIS, but I already converted it to a world cities GeoPackage so you can just download that directly and add it to QGIS if you want to follow along here. There are over 26,000 places in the file though, so when you add it you'll see too many places to make sense of - but we'll filter the layer to sort that out in a moment. For now, here's what the whole lot looks like.

Lots and lots of dots

Okay, so this is fairly typical when we add a cities or places layer to QGIS - or indeed any GIS software. We're overwhelmed with dots so we need to think about how to filter it somehow. That's next.


Filtering the data

Before we label, let's filter the data. You can use the columns (also known as Fields) in the Attribute Table to filter the data - and you can see below that I've done this using "capital" = 'primary' so that only capital cities are showing on the map.

Okay, this is looking a bit better

But let's say we only want larger capital cities to appear - e.g. those with more people. We can use the population field in the dataset to filter further, like I've done below to show only capital cities with 1 million people or more.

You can see how to use the AND operator here

We also have a latitude and longitude column in this dataset, so we can use that to filter the data too. This time I'm going to filter it to show only those cities within 10 degrees of the equator that have more than 1 million people (according to the population column in our dataset).

You can filter using any of the columns in your dataset


One more filter now - this time we're looking at cities in Brazil, Australia, Canada and Japan with more than 700000 people - according to the simplemaps dataset.

Using IN as well as AND this time

What about labelling? 

This post is supposed to be about labelling, so let's talk about that in a moment. I just want to emphasise that BEFORE doing any labelling it really is worth thinking about what you want to label - and how many features there are as well as where exactly they are - e.g. are they overlapping?

I wrote a filter expression so that I'm only showing the cities you saw at the top of the post - a selection of cities on or close to the Pacific Ocean. 

I filtered the dataset to focus on only a few cities


The next few images show you what label settings I've used here - a variety of different methods, including a slightly transparent white background to the labels.

I'm using the city field to label the cities, size 14 font

Note the Size X and Y variables, and the Radius X, Y too

Drop shadow on the labels, with Opacity turned down

I've moved the labels away from the symbols a bit here


Visual hierarchy

There are so many things you can do with labels in QGIS, but one really useful thing is the ability to set the size of labels based on a variable. So let's do this with the cities above so that larger cities have bigger labels. There are many ways to achieve this but I'll do it a fairly simple way. I'm using the Data defined override button beside the Text size option, as you can see below. Look at the expression I've used and you'll see how I modified the size of the labels this way, starting off initially with just Tokyo being in large font.

The Edit button (via the Size section) is how I change things

Note the format of this - e.g. CASE, WHEN, ELSE, END

Now I'm starting to get a more useful visual label hierarchy

Now in the map below I've made the largest cities a different colour, using the same kind of approach - as you can see.

I'd normally use just a single colour, but you don't have to

In the example below, I'm only using a label background on cities with more than 5 million people, using the same kind of approach.

Note the 1 and 0 values here, where 1 = true

And then in the final image below I've added a thin line around the label backgrounds, just to make it a little bit crisper on the screen.

This require a few clicks, as well as editing the Stroke style

Here's the final version of this simple label map experiment, in high resolution. What I'd normally do beyond the labelling is also apply some kind of size hierarchy to the city symbols, and this can be done using exactly the same approach - i.e. edit the symbol size using the Data defined override and then setting it based on city populations or city names - or whatever variable you want.

Hopefully this has been useful for you


That's all for today, but if you're new to it and need some help, feel free to get in touch.

Monday, 30 May 2022

Let's play Urble!

Today I'm letting Urble out into the wild. It's a little geography game in which a new city (displayed as a small square) appears every 5 seconds until there are 10 dots on screen (example below). The aim of Urble is to guess the country before the country shape appears - 50 seconds into the video. You can pause the video after the 10th dot (at 45 seconds) if you need more time. If you turn the sound on, you'll notice that when the 10th city is added it makes a different sound. I'm releasing this in video format, just for fun, so people can play it how they want to, and share them across platforms - I have lots of them! Some you might find easy, others no so much. As you might be able to tell, Wordle is part of the inspiration here, hence the colours. You'll see more on my Twitter, where I'll post each Urble using the hashtag #urble. I may give clues for some of the more difficult Urbles.

Are you a map genius?


This is what the end of an Urble looks like

As well as posting these on my Twitter (@undertheraedar) I'll also put each one in The Urble Archive too. Each Urble is numbered, so it's easier to keep track of them, and of course I won't keep you guessing forever - the answer is always revealed 5 seconds before the end of each video. They're all 60 seconds long, so you can get on with the rest of your day, or pause the Urble on 10 dots until you figure it out.

Here's Urble 1 - always best viewed with sound on (there's no music, just a few sound effects). There's also a gif version of each Urble, which I will also post in the archive - you'll always find the original, high-quality Urbles there. Can you guess which country this first one is?


You can see the full size, high-resolution video on The Urble Archive, where I'll put all Urbles after I share them on Twitter.


Urble - why?

Well, I make maps and look at geographic data a lot, and I'd always thought about doing some kind of fun game in a more formalised way. From time to time I've posted geography guessing games on my Twitter but until recently hadn't ever made something like Urble - but now I have. I've been playing this at home so far with my two sons and my wife, and since they like it I'm releasing it into the world now. In fact, my 9 year old son Isaac actually made a few of them himself, with me at his side giving instructions as he put them together in QGIS and Camtasia.

I've said more about Urble in the About file on The Urble Archive page. If you have a question, it may be answered below. Otherwise, check the About file.

The answer to the main 'why?' question here is that it's for fun, but also hopefully educational.


Questions you may have about Urble

What tools did you use to make Urble? I used QGIS for all the map stuff and Camtasia to create the mp4 and gif files. If you want to learn how to use QGIS, check out my Map Academy course on Udemy.

Surely you'll run out of countries pretty quickly? Well, this is sort of true but I can easily re-use countries by selecting a different configuration of cities, in a different order. Watch out for this as new Urbles are released. Maybe I'll repeat countries. Be mindful of this.

What about a country with more than one official capital? Good question. There aren't many of these, but where I do have an Urble for a country with more than one capital, I will only show one of them and it will still be the third city to appear, always as a green square. I will not show other capitals in the same Urble.

How do you decide which cities to show? The capital city is always included, as well as nine other cities that are - usually - among the top 30 by population in a country. In general, I try to make sure the cities give some hint to the shape of the country, but at times you'll need to wait until the 8th or 9th city to see it. Occasionally I add in other cities that help me show the shape of a country, even if they are smaller settlements. But this is the exception.

Why don't you add the city names at the end? Because part of Urble is guessing the cities as well as the countries. At the end you can try to figure it out, if you want to. I also want Urble to be as accessible as possible for an international audience, and adding more text (using place names written in English) wouldn't help with that. 

How do I win? I consider a true 'win' to be any Urble where you figure out what the country is before the country shape appears - i.e. before 50 seconds are up. But if you get it after pausing the video before the country shape appears, you can still count yourself a winner. In fact, if you don't get the country at all but you learn something new, then maybe you can count that as a kind of win as well. If you get the country before the capital appears, you are a true genius. If you get it before the fifth city appears, I salute you!

Can I steal Urble? Please don't, but I don't mind if people share Urbles, with a link back to my Twitter, The Urble Archive, or this page. 

Why didn't you make this into a website? I was going to, but in the end I decided it would be too much bother and actually I like the video-only approach as it's easier to share across different platforms and I don't have to mess around with code that I barely understand. I quite like the fact that you have 60 seconds to guess and also that you can just pause if you need more time.

Surely some countries will be impossible to guess? Well, I suppose that all depends where you're from and what you know. But even so, it is undoubtedly true that some countries are much more well known than others by the majority of people. But I see this as part of the fun - as an Urble unfolds, your brain is working overtime trying to figure out the country shape, country size, configuration of cities, possible patterns (e.g. coastal? river? borders?) and you're against the clock. If you're from Mongolia then you'll probably find it easy to guess Mongolia, but if you know nothing about Mongolia then you'll find it very difficult! But that's okay because if you do an Urble for Mongolia you'll learn something new.

Hasn't someone done this before? I wouldn't be surprised but when I went looking I couldn't find anything that looked like Urble. Lots of map quizzes and geography games online, but I didn't see anything Urble-esque. Obviously we have things like Worldle but that's a different kind of geography game where you guess the country from one big shape. This is something I thought about back in January 2022 when I made a few silly maps for Twitter (one of which is shown below).

This is not Urble


Happy Urbling!


Saturday, 21 May 2022

English Green Belt Atlas, v5

Where is the green belt? Where are the green belts? How much of my area is green belt land? These are excellent questions, but it's not always super easy to find the answer, and that's why I originally began investigating this topic back in 2012. This then eventually led to me producing maps for each English local authority that had green belt land in it, thanks to an idea suggested to me by geo legend Prof Bob Barr. Since I last did this in 2018 the number of local authorities in England has changed and there is a more recent green belt dataset, so I'm returning now with version 5 of my English Green Belt Atlas. Currently, 12.4% of land in England is designated as green belt, across 180 local authorities, but it varies a lot between places, as you can see below. I have made one map for each of the 180 areas, listed alphabetically (they are really high resolution images). How big is 12.4% of England? It's 16,140 square kilometres or 6,232 square miles. This is just a little bigger than the South East region or Yorkshire and the Humber, and about 80% the size of Wales, just to give a sense of scale. From 2020 to 2021 there was a 0.1% decrease in the amount of green belt land.

I did my best with the labelling

I've tried to keep the maps fairly simple


An example of a very split local authority area (rail line)


This area has the highest % green belt land in England


Not an awful lot of green belt land here


Okay, so you get the idea with the maps - I've shown rail lines (dark), railways stations (little circle dots), places (square dots, different sizes), major roads (orange), buildings (dark), water, green space (light blue) and green belt land in a darker green. The little dot in the bottom right inset map shows you where a local authority is, just in case any are not familiar. I've automated the labelling but it's not 100% perfect, but I can't spend any more time on it. Want to use one of these maps, or all of them? Be my guest.

Here's a few more that I found interesting. You can find the full set, listed alphabetically, right here.

























Sunday, 15 May 2022

The Geography of REF2021

Over the past few decades, UK universities and other higher education institutions have been subject to an assessment of their research quality through something called the Research Assessment Exercise (RAE) and more recently the Research Excellence Framework (REF). When I got an academic job at the University of Sheffield in 2008, it was probably because my last name is Rae and the year was 2008 and they thought I'd be good for their RAE2008 profile. Anyway, I left my academic job a couple of years ago and now run my own spatial data and training company but I did have one eye on the REF2021 results because some of my work was in it (papers, plus an impact case study). 


A lot can and has been said about REF, good and bad (okay, mostly bad), but here I'm taking a brief look at the geography of the results, by the 34 units of assessment (UoA). Here's what you'll find below.

  1. Maps showing the basic geography of each UoA.
  2. Maps showing where the top ranked institutions in each UoA are.
  3. The number of REF institutions by local authority (that's the preview image above).
But before we get going, here's the general overview showing the size of each institution's REF2021 submission in terms of staff numbers (and remember that in most cases the total % of academic staff submitted is less than the total number working at any individual university).

Lots of big blobs here


As always, click on an image to see it full size and if you want to use any of these images, just go ahead, no need to get in touch. I've added a few technical notes at the very bottom of the post. Now, click a map, then flick through the images - there are lots of them.

The basic geography of REF2021






































































Top ranked institutions, by UoA






































































Institutions by local authority


I was just curious about this




I didn't quite realise how many there were here



Notes: the source for this is the official spreadsheet published on the REF2021 results page on 12 May 2022. For most institutions (mainly Universities of course, but some are not - e.g. The Institute of Zoology, The Royal Academy of Music) the location is fairly clear-cut but bear in mind that some institutions can be spread out over different locations, sometimes far apart - as in the case of the University of the Highlands and Islands with the HQ in Inverness but colleges spread throughout the region. What does 4* mean, anyway? Good question. Here, it just means that the REF panel decided that's what it was, so that's what is on the map. Sometimes the number of institutions or UoAs you see on a map may not exactly match what you may find in your own calculations, depending upon how you do them - this would be due to joint submissions from multiple institutions. Spotted an error? Feel free to let me know. Hate REF? I understand.