Showing posts with label GHSL. Show all posts
Showing posts with label GHSL. Show all posts

Sunday, 28 November 2021

World Population by Latitude

If you search online for 'world population by latitude' you'll quickly find quite a few results, including the great analysis by Bill Rankin on his Radical Cartography blog from 2008, which uses population from 2000, and also includes population by longitude. There's also a nice interactive version on Engaging Data, plus similar things on my One Degree of Population piece on here a couple of years ago and my global population density spike maps. In this post I look at world population by single degree of latitude using data from 2020. There are maps and stats below, but let's begin by looking at what appears to be some kind of alien eyeball but is in fact world population by single degree of latitude, where redder areas = more people at that latitude and bluer areas = less people. I used 2020 WorldPop data to do the calculations and all the maps were done in QGIS, as usual.

Weird alien eyeball? Or population map?

It's better viewed as a flat map, obviously, so I've posted that below. I've labelled quite a few places across the world and of course there are places at some highly populated latitudes that have very few people (notably the Sahara Desert) but you get the idea here: redder = more people at a given latitude.


Note the numbers on the left - including population data

If you view this image in full size you should be able to read the population numbers for each single degree of latitude - I've posted a zoomed in extract of this below. The most highly populated single degrees of latitude, according to my analysis? Here are the top 10 that I get:

  1. 25-26° North: 278.6 million people
  2. 26-27° North: 271.7m
  3. 23-24° North: 244.5m
  4. 24-25° North: 237.4m
  5. 22-23° North: 235.3m
  6. 30-31° North: 234.8m
  7. 31-32° North: 226.2m
  8. 34-35° North: 215.8m
  9. 35-36° North: 214.6m
  10. 27-28° North: 198.3m
And then down in 28th place we have the first entry in the southern hemisphere with 6-7° South having a population of 117.5 million people, according to my calculations. 


These are numbers I calculated myself

It's difficult to do anything with this colour scale these days without bringing to mind Ed Hawkins' warming stripes, but I think it's useful to use the red/blue colour ramp here because the most highly populated places are generally the warmer ones and the colder latitudes on the whole have fewer people. But of course there's another factor here, and that is about where all the land is. So first let's look at land vs population and then we can look at a density version of the above map - i.e. population density by latitude that presents the stripes based on the population density of land at all the different latitudes.


This is what I get for land by latitude


And population by latitude - people don't like living in the sea

You can do a little crossfaded gif to get the comparison between these two different elements, so that's what I did below. You can see it in the still images above, and in the gif below I have highlighted the single degree of latitude with most people and most land. 


Finally, we have a population/land by latitude gif

Let's hit pause on the gif, mid-fade, and then add some labels so we can make a bit more sense of what's going on. That's what I've done below - click to enlarge in order to read the labels.



Here's another globe-style view of the population data but this time from a different perspective.


Some surprises here perhaps

Okay, so the next three images are similar to the 'world population by latitude' image above but this time they are actually population density by latitude. That is, the redder latitudes are the most densely populated. I did this so that it only takes into account land, which is kind of where people like to live for some reason. You'll note in particular here there is a dark red stripe in the southern hemisphere that cuts across Santiago, Buenos Aires, Cape Town and Sydney, among other places. Note that I experimented by dimming and then removing the latitude colours over the sea in the second and third images because it kind of makes sense to do that.


Density makes a bit more sense

Dimmed the sea because people don't live there

Removed the sea latitudes, but I like this less


Other odds and ends

Once I'd done this I experimented with different map projections and views, hence the weird population latitude eyeball at the top of the piece. I also experimented with views from above and from below, so you can see them below in the first two images. The first one in particular looks like a bloodshot eyeball to me.


Where do most people live? Just eyeball it

Antarctica is pretty big

What else? Well, I did a few other versions, including just coloured lines of latitude, then adding only land, adding a chart and that kind of thing so I've posted them below too. These are more experimental versions - some I like more than others but the one with just colours and land I think is quite interesting.


Population stripes, with land

Just the population stripes

I took away only the land here

In this one I just added a chart of population by latitude

This is the original, as above, but without a white border

Does the final result on all this depend upon what dataset you use? Do you get a different result by using, say GHSL data vs WorldPop data? Or what about NASA's GPWv4, or even another source? Well, probably a bit, but the difference between GHSL and WorldPop wasn't huge and WorldPop is also available for 2020 and GHSL isn't so I used WorldPop. But you can see the difference between GHSL and WorldPop below anyway.


GHSL

WorldPop

GHSL WorldPop GHSL WorldPop GHSL WorldP

This all basically makes sense and is not particularly surprising but then again it's nice to be able to put some numbers to all this and make some maps of it. Plus it's interesting for training data and for working on map methods and techniques in QGIS.

People live here

Here's a screenshot of what this looked like in QGIS before I exported some of the final images. The font is Righteous, by the way.


Print Layout on left, map view on right


So there we have it. 

Thursday, 12 November 2020

How to make a 3D population density render for any country in the world

This blog post explains how to make a 3D population density render for any country in the world, using open data and free software. The main tool I'll use (Aerialod) is Windows-only at the moment, but it is amazing. I say 'render' rather than 'map' here because the images you'll generate are rendered by Aerialod, which is, technically, a 'path tracing renderer' rather than a piece of mapping software. But feel free to call them 3D maps - either way, this is an example of what they look like. 

Global population density print


But why do this? Well, partly because it's an interesting and often informative way at looking at population and settlement patterns, but also partly because this particular method produces nice-looking graphics. Perhaps the best answer I could give here is that's it's a combination of aesthetics, insight, and interest. In the image below, for example, we can see a lot of what we might already know, but it's often in the comparisons within and between places that we learn new things and that's also part of the point here - it can give us a new perspective on the world.

Singapore, KL, Medan, Ho Chi Minh City, etc


The ingredients

What do we need to make a population density map like this of a single country? Well, it can be done in different ways, and you may have your own method, but the basic ingredients are outlined below. I'm going to use the example of the United Kingdom as a single country, but the data source I use has data for all countries in the world, so you can pick whatever you like and replicate the method. So, here's what we need:

  • Some population data, preferably in raster format
  • A tool to render it in 3D
For the data, there are a few different sources, including the European Commission's GHSL data and NASA's GPWv4 but here we're going to use WorldPop population density data. These datasets are all free and open (CC BY 4.0), and all have 1km resolution versions, but WorldPop allows you to download individual countries, for each of the years from 2000 to 2020, so I'll use that here. Just a note of caution now to say that '1km' means '1km at the equator', or 30-arc-seconds - so if you're at 50 degrees north then the cell will still be 1km in height but it will only be about 80% of that width. Also, you should read the WorldPop - Mapping Populations page about the data, so that you understand what it is, and how it was created.

For rendering the world as a 3D population surface, there are again lots of options, the best of which is probably Blender. This is free, open source and extremely powerful but it's not what I'm using here. Instead, I'm using Aerialod by @ephtracy. I've previously written tutorials on how to use this for different kinds of data, but here' I'll focus on population density renders. 


About the vertical dimension of population density datasets

You can just download some data from WorldPop for a single country, in tif or asc format, and then just dump it in Aerialod, but when you do that with population data, something like this will probably be the result (below). This is the 2020 UK population density file from WorldPop, opened in Aerialod. I'm showing you this here as a way of explaining what Aerialod does and what you need to understand before you try to map population density in this way. 

What the tif?


The gbr_pd_2020_1km.tif file from WorldPop (2,372KB) is a simple black and white raster image, measuring 1,250 by 1,321 pixels (you can see this in the image properties when you download it). But the individual pixel values have population counts in them. So, when I open the file and inspect it in QGIS (below) I can see that the highest pixel value is 27,500 - and since Aerialod extrudes the vertical dimension according to individual pixel values, what we see in the image above when we open it in Aerialod is a kind of population density tower 27,500 high and only 1,250 wide by 1,321 high. Not exactly very useful. So, we have a 1km area of London with 27,000 people in it and this then gets extruded 27,500 units on the z dimension in Aerialod, while our x and y units max out at 1,250 and 1,321 respectively. Next step is to fix this.

We need to re-scale this file in order to use it


Scaling population density data in QGIS

This is probably the most important bit. I will say now that there are lots of different ways to do this next bit, but ultimately what we are trying to do is arrive at a situation where we can show population density patterns in 3D that provide a useful overview of the settlement patterns in different countries, or the world as a whole. I used a different approach in the image at the top of this blog post, plus different data (GHSL), but it is based on the same principle. The following is a simple workflow to take a tif file from WorldPop and then rescale it so you can use it in Aerialod. If you were mapping something with much lower actual values (e.g. elevation) then you don't need to do this re-scaling.

  • Open the population density tif in QGIS. It should just display as a black-to-white image, with low population counts in darker colours and lighter shades for the highest values. You can see this in the screenshot from QGIS above.
  • Right-click the layer > Export > Save As... and then you want to change the Output mode to Rendered image, select a folder to save it to, plus a file name, and then click OK. This will add another raster layer to QGIS. You can see a screenshot of this below.
  • You'll see that the new raster layer in QGIS looks exactly the same, but it's not. Instead of the actual population values in each pixel, the values go from 0 to 198. This is what the Rendered image save option does - it scales the image using pixel values in the range from 0 to 255, where 0 is black and 255 is white. 

Saving as a rendered image

  • When we add this new rendered image to Aerialod, and then change some of the settings (as in the screenshot below), we do get quite a good visual representation of population density.
  • But, there's no land and the old 0 to 27,500 range has essentially been reclassified from 0 to 198, which means that the full range of classes (up to 250) hasn't been used. We'll fix that in a minute but first here's the result, below. As you can see, this does a pretty good job of illustrating the broad sweep of population density across the UK. If you're struggling with Aerialod here, you may need to go back to the links at the top of the page and see my tutorials on it, but all I did here was drag and drop the tif into the main Aerialod window and then change the settings, as per the screenshot.
This works pretty well - but there's no land


How do we get the land to appear? (don't use black for 0)

This next bit is about how to change the raster image before exporting it so that when we add it to Aerialod we can see the land as well. There are loads of ways to do this, but here's one simple way that works well. This step is only really necessary if you want land to appear. I prefer doing this because it then gives me the option of including the land, or not (i.e. you can make the land disappear by changing the Offset value in Aerialod to something like -2.0 in this case). 

  • Go to the original raster layer (in our case the one that goes from 0 to 27,500) and then in the Layer Properties, Symbology section, we change the Render type to Singleband pseudocolor. 
  • What you need to do here is edit the colours so that the ramp goes from almost black (but NOT black - so don't use RGB 0, 0, 0 or #000000) to white. Aerialod will interpret the darkest colours as low values and white as the highest values - see below for a screenshot on this.
This is one way to do it


  • Once you've done this, you can then save the layer as a Rendered image from QGIS, just like we did above. It will then add a new dark to light raster layer to QGIS, just like before. Unlike before, however, when you click on a cell in QGIS with the Identify Features (i) tool, you'll get a value from just above 0 to 255, instead of the population count. 
  • Check: are all your highest population spikes the same height, meaning they look truncated or flat-topped? If so, this means you probably need to adjust the light-dark colour gradient again in QGIS before exporting it and loading it in QGIS. This sometimes happens in the highest density areas so it's worth looking closely at it and then if it does happen, re-scale the data in QGIS using a different kind of classification (e.g. instead of Continuous you could try equal Interval or even Quantile). Also, just remember that this approach is quite a simplified visualisation approach to displaying population density data. The vertical extrusion is not super-precise, and of course depends upon the method you use to create the rendered tif. The idea with the approach outlined here is to give a good general overview of population distribution and density in a country.
  • N.B. there are loads of different ways you could do this step, including the use of different colour ramp modes (e.g. continuous, equal interval, quantile) or you could re-classify the raster using a scaling factor (e.g. divide all values by 1,000), or do it in an image program, but here I am aiming at simplicity and a method that allows us to quickly arrive at a result that is both interesting and broadly representative of the spatial patterns of density on the ground. 
  • So, what does it look like when we add it to Aerialod now? Well, see below for the new image.
Reduce the Offset (on the right) to remove the land


The point of this is to be able to create a 3D render of population density in any country, and this is one way of achieving that. For things like this, where I am striving for broad-brush patterns and workflow efficiency, rather than precise measurement from pixel values, I will often take shortcuts to achieve what I want - so for example, in the image below I have 'reprojected' the data by manually re-sizing it in IrfanView and then saving it as a png file, which ended up being 289KB in size. Try downloading it and dropping it into Aerialod and then replicate the settings I've used below - I think this one has the makings of something quite nice, and you can replicate it for any country. I have also added a similar file for France (as of 21 Nov 2020).

All this from a 289KB png file + Aerialod


I want to map the whole world this way!

Okay, no problem. You can get global population density layers in a few places, but probably the most convenient are WorldPop or GHSL. The WorldPop ones can be found at the bottom of this page - look for the 'Unconstrained global mosaics' link. For the Global Human Settlement Layer (GHSL) data, published by the European Commission, you'll want to head to their excellent Download page. Once again, I'd advise anyone using this data, or any kind of data, to read about what it is and in this instance the FAQ page is particularly useful. 

Most of my population density mapping in the past has used GHSL data. One great thing about the GHSL download options is the ability to pick different projections, so that you don't just have to use WGS84 - this is still good, but the further you go from the equator, the narrower the area represented by each cell. This is not the case with the Mollweide option, since it is an equal-area projection. But this is something you should look into further yourself if you're interested. 

If you do download a global file, you need to be aware that Aerialod can handle images at a maximum of 16,384 pixels in width or height, and the world is more than 16,384km wide. So, if you do download a global population raster, you will need to re-size it in whatever software you use (I always use IrfanView for this) so that it is less than the maximum pixel size allowed in Aerialod - I normally just re-size to 16,000 pixels. 

This means that the 1km cells are no longer 1km but closer to 2km, but at a global scale the pattern is very similar. I've created a small-file-size global raster (2.21MB), with the Pacific in the middle rather than the Greenwich Meridian, and shared it via Dropbox so that you can experiment with it as well. See below for what it looks like when you drop it in to Aerialod with the settings as per the screenshots.

This is the whole world, from a 2.2MB png


Zoomed in, and exaggerated heights


Recap

I could say a lot more about methods and how to tweak this and that, but the aim of this post was just to show you how to create a 3D population density render of any country in the world, and I've done that now, using the United Kingdom as the example country. All I would add is that if you're struggling with Aerialod, then you should go back to my original blog post on it, plus the earlier one linked to in it. It's definitely also worth spending time reading about the data sources I have mentioned.

I hope you have found this useful. If you get a lot of use out of Aerialod, and you are able to, perhaps consider making a donation to @ephtracy - the creator of this great piece of software. I have done so in the past and hope to do so again in the future.


Data sources

I've linked to the data sources throughout this post, but I'll do it again here so they're all in the same place. This is all open data, with each one licenced under the Creative Commons - Attribution 4.0 licence (CC BY 4.0). 

  • Worldpop.org - WorldPop really is an amazing project and in fact one of the best data resources currently in existence, in my opinion. It has so much beyond population data, so even if you don't want to map population patterns it's 100% worth checking out. Note that in the data section of the website you'll see both 'Population Density' and 'Population Count' but here I've used the population density data. It's worth spending some time on the website to see what's available and also to understand what the data represent and how it is all collected. You can get this data either as a tif, like I've used above, or as a csv file.
  • Also one of the best population data resources currently in existence, the Global Human Settlment Layer has the advantage of going further back in time, with a total of four time points - 1975, 1990, 2000 and 2014. The GHSL project is supported by the Joint Research Centre (JRC) and the DG for Regional and Urban Policy (DG REGIO) of the European Commission, together with the international partnership GEO Human Planet Initiative. If you download this data, there are LOTS of options, but what you need if you want to map population density is the GHS-POP option. I've mostly used the 2015 data, at 1km resolution, in Mollweide or WGS84 projection for the whole earth, but you can also just download single tiles. This data is available in tif format.
  • NASA's Gridded Population of the World, version 4 - another excellent source of global population data. The GPW v4 home page explains everything about it, and all the different variants available, as well as previous versions. 



Wednesday, 29 April 2020

Population density in Europe

Population density is a subject I've been writing about for a while, so I decided to create a few more renders of European population density using the EU's GHS_POP data, which is freely available. The maps below use 1km x 1km data and the height of the bars represents the number of people living in any one square. The big squares are 50km x 50km (about 30 miles) and are there to provide sense of scale. The highest 1km densities are found in Spain and France, and Madrid, Barcelona and Paris in particular where you get values of more than 50,000. You can read more on that in a previous piece I did on the topic. Anyway, enough words for now - see below for the six different renders I created; I've tried to create a few interesting perspectives here. Scroll below the images for a bit more technical information about the process and the data.








Why do this?
I did these because I find it a useful way of understanding wider patterns and the bird's-eye view gives a nice sense of perspective over a large area. But of course with 3D mapping it's always a bit of a balancing act because turn the map one way and you inevitably obscure something or somewhere of interest to people. Although, in this case, it is more experimental and aesthetic than analytical, which I think is okay sometimes. 

The data for my area look wrong!
This may be the case because after all the quality of any kind of visualisation like this depends upon the data inputs. Anyway, the data come from the EU's Global Human Settlement project and are available for different years. I'm using the 2015 data here, and you can read more about it and get the data yourself at their excellent new download pages - and do read the documentation, which is also great.

Data processing and mapping
I downloaded the entire global 1km dataset and then in QGIS I clipped out an area focusing on Europe and then extracted it as a rendered tif. If that means nothing to you, don't worry! It should be helpful to anyone who wants to replicate this. I then imported the data into Aerialod and spent some time tweaking lots of different settings and I wanted to give Europe a nice hopeful glow effect. 

Should I give away my trade secrets on what settings and colours I used here? Of course I should - see below.




This is a difficult time right now, and I'm always looking for alternatives to doomscrolling, so I hope you find these interesting to look at - I found them interesting to make!

Wednesday, 26 December 2018

One degree of population

Here I am at the end of the year with another bit of map fun, this time inspired by Bill Rankin's world population histograms from 2008 (check out his website if you haven't already - it's amazing). For no good reason, other than curiosity, I decided to do some mapping of the world's population by single degrees of latitude and longitude. Actually, curiosity is I think quite a good reason, so see the first graphic below, making sure to read the caution on the map (tl:dr not all cells are the same size). Update 28 December 2018 - I added a version doing it by longitude as well. There's a gif at the bottom of the page and the mp4 files are in the repo I link to below. I also did a backwards-forwards looping gif - see below.

I think this backwards and forwards version works well

It makes more sense to compare areas at the same latitude

In the image above, I've picked out the ten most highly populated 1 degree cells but of course they are not all the same size - they get smaller the further away from the equator you are, because the lines of longitude narrow towards the poles. But even so, I think it's probably safe to say the cell where New Delhi is has a lot of people in it, as do the other nine featured above.

Now, we all know that most of the world's population live in the northern hemisphere (I make it about 87%), which is hardly a surprise because that's where most of the land is (68%) but I thought it would be interesting to do an animation of the above map, and that's exactly what I did. Here are some stills from the animation (below) and here is a direct link to the repository where I've put a 15, 30 and a 60 second animation. You'll probably have to download the files before viewing them.

Before that, I've embedded a version from YouTube, with an audio track.



If you live below 30 degrees south you are quite special

People seem to like living where the land is

Above 30 degrees north is where it's at 
I'm one of the 5% - are you?



And by longitude? I did that too and those files are at the GitHub repo link above but here's a fast gif of it for now.



How I did this
The data I used for this is the GHSL world population dataset that I've written about before. I've been using it recently in a paper so thought I'd do something a little different with it. This is the latest data, for 2014. I used the 1km gridded population dataset and re-aggregated it by lat/long so it's not a precise match with lines of latitude and longitude but it's close enough to be a reasonable estimate. I mapped it in QGIS and exported a few thousand frames in QGIS Atlas then patched the video together using FFmpeg.


Sunday, 28 January 2018

The Most Densely Populated Square Kilometre in 39 European Countries

A few days ago I published a short piece in The Conversation about population density across Europe, based on EU gridded population data. This was really my attempt to see if I could produce some numbers which better reflect the experience of population density across Europe, rather than just the raw arithmetic average. At the end of the piece I added a table with some stats, including the maximum 1km population density for each of the 39 countries I looked at. There wasn't space in the article to tell you where all these places were, so I'm doing it here instead. So, without further ado, here are the most densely populated 1km squares in each of the 39 countries, from Spain to Liechtenstein. Click to enlarge.









































I did this quickly so it's a bit rough and ready as far as the maps go - a few labelling blips here and there but you can get the idea. Scrolling through from most dense to least dense does generally seem to make sense visually though you can't always tell what's what because some places have lots of high rises in them and you don't get a sense of that from the aerial photos.


Notes: the data are from 2011, so a little old now. We should also really consider these estimates, for a variety of reasons, but I think they are likely to be close to truth, based on my analysis of similar datasets (e.g. ONS in the UK and GHSL globally). Note that if you download the EU data you'll have to then join it to some kind of geodata (e.g. shapefile) because it's not already done. This can be tricky with about 2 million 1km cells and rows of data. Why are England, Northern Ireland, Scotland and Northern Ireland separate here? That's just the way they published the data. But I found it useful to get a better look at patterns in different parts of the UK.