Showing posts with label places. Show all posts
Showing posts with label places. Show all posts

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.

Sunday, 23 February 2020

A few flow maps + data to play with

I've written a fair bit about mapping flows (e.g. migration, commuting) over the past decade or more and here I am again. The point of this post is to a) share some data so that anyone who wants to play with it can have a go; b) talk a little bit about visualising flows; and c) to look at the functional economic geography of England.

First of all, here's the underlying data - it's 2011 MSOA-to-MSOA commute data for England and Wales, which comes from the Census. Yes, it's getting quite old now but it's still a useful dataset. It's a big shapefile, with columns for total commute flow between LSOA and also different modes (train, bus etc) and some other stuff (e.g. distance, area codes and names).

Here are some of the maps I extracted from it. The lines are the commuting connections between places, with an addition blend mode added in QGIS, plus a scaling factor is used to make smaller flows dimmer and larger flows brighter. I've filtered the dataset to show only MSOA-MSOA flows of 10 or greater, otherwise it's a total mess. Here are some of the maps.










Okay, lots of shiny maps to see. With the opacity of the lines set to reflect the volume of the flows you get a slightly better overview of commute patterns. The addition blend mode gives the shiny effect, which is in some ways just a bit fancy but actually it serves a purpose here: making the main economic centres brighter, which fits in well with the underlying economic geography of England and Wales.

Talking of the functional economic geography of England more broadly, there are connections to my previous work with Garrett Nelson on US megaregions (e.g. our interactive map site, with similar shiny maps but driven by an algorithmic partitioning process) and you can get a sense of where the break points are between different areas.

Talking of which, if you're interested in this kind of thing, check out the AMA Garrett and I did on Reddit about the US commute work as part of the PLOS Science Wednesday series. The comments here are pretty interesting, particularly those from commuters about where they draw the line themselves between travelling to city A vs city B.

That's all for today - feel free to download the data and have a play, use the maps as you see fit, or get back to me with any questions or suggestions.

Oh, and if you do download the dataset, you'll also see that I have added origin an destination codes and names for MSOAs and local authorities. This is useful if you want to, for example, only look at all flows into Manchester, or all flows between Leeds and Bradford.


Data notes: MSOAs are small geogaphic areas with between 5,000 and 15,000 people in them, or between 2,000 and 6,000 households. Most have about 8,000 people and 95% of MSOAs had a population of between 5,443 and 11,579 at the time of this dataset is from. Want to know how to do this in QGIS? See my flow map tutorial from a few years ago. Want to know more about the glow effect? See this tutorial on glowing lines in QGIS. And the place labels? I put together a single file of Great Britain place names if you want to use that. I've used a couple of rules on which places to display, plus added some in manually. Thanks to Allan Walker and Richard Mann for making me think a bit more about this again.

Thursday, 30 August 2018

10x10km City Squares

I've been thinking about little projects I could do with the Great Britain buildings GeoPackage I shared previously on here and have come up with the idea of comparing the urban fabric across the country. For this I drew inspiration from previous work by Geoff Boeing, though instead of 1 square mile of urban fabric, the images below are 10x10km squares. Look at the gif first, then I'll explain the method and share all the static images. All images are ordered roughly from north to south so we start in Inverness and end in Canterbury. Update: 1 Sept 2018. I decided to manually select 144 towns and cities and do a 12x12 version of the original city mosaic below, just to make it more interesting. if the image below crashes your browser, try this smaller one. Want all the individual tiles? I put them all here in a Dropbox folder.


Click to enlarge - huge version (12,000 x 12,000) here


65 cities, at two seconds per frame (squares are 10 x 10km)

What I did here was take some Ordnance Survey open data on places in Great Britain and then filter it so that only places with an 'Extra Large' place label were visible. See this blog post for an explanation of what that means. This left me with the 65 cities you see in the graphic above. The image below has 64 just because I wanted to do a 8x8 version. In all these images all I have shown is the most detailed buildings layer available as open data from Ordnance Survey - you can download the lot from my buildings page


10 x 10 km squares for 64 British cities

The centre point of each square is where the Ordnance Survey place label is located. If you moved things north or south, or east or west in some cases you'd get a bit of a different picture but the points are generally in the centre of these places.

I've posted all the individual images below in case anyone is interested. This was also a bit of a test for QGIS and I did actually do about 1,600 of them just to see how my computer would handle it so if you're really sad that your town or city isn't on here let me know and I'll share it.

Method: in case anyone is interested this was done in QGIS Atlas with Ordnance Survey open data, and ImageMagick for the layout. I tend to use IrfanView for batch resizing and so used that here. The font - Raleway - is from the free Google font pack available online. The colour is #222222 (RGB 34, 34, 34).

That's all for now.