Monday 2 September 2019

Globe projections and insets in QGIS

Update, January 2022: this tutorial may still work (although you will also notice a WKT option in the projection settings now, and the proj method is not recommended any more) but what I'd really recommend is that you use the Globe Builder Plugin (just go to the Plugins menu in QGIS and search for it). 

Proper QGIS boffins may remember Hamish Campbell's excellent post on the topic of 'Azimuth Orthographic Projections with QGIS' from 2014, in which he described a method for creating maps with an azimuthal orthographic projection - or, what non-boffins might call a 'globe view'. The good news is that in QGIS 3.4 you can do this very easily using the built in The_World_From_Space projection and you can easily create new ones with the view of the world you want. See below for an example and then read on for the method. The great thing is that you can also have a globe view and a normal, flat view in the same Print Layout as QGIS now supports multiple projections in the same layout.

The graticules are from Natural Earth

Okay, how to find this 'world from space' projection? The easiest way is to click the little CRS button at the bottom right of the QGIS window, or go via Project > Properties > CRS. Then you just search for it in the CRS search box, as you can see in the screenshot below - where you'll also see a couple of modified CRS versions I created. Just in case you don't know, CRS stands for coordinate reference system and they all have an EPSG code so that's why you'll see 'EPSG' and some numbers. If you're a proper carto boffin you'll know your 4326 from your 3347.

You can see the properties of the projection here

Okay, so that's how you set it. How to create a view centred on where you want? For that, you first need to copy a bit of the text in the above box, which I've pasted below so you can try it yourself.

First, copy this text: 

+proj=ortho +lat_0=42.5333333333 +lon_0=-0.53333333339999 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs

Then replace the 42.5333333333 wih the latitude you want and the -0.53333333339999 with the longitude you want. You don't need so many decimal places! So, for example, I did this for New Zealand and this gives me:

+proj=ortho +lat_0=-40.5333333333 +lon_0=-157.3333333339999 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs

You can see by looking at the numbers above that I have centred the projection on 40 degrees south and 157 degrees east. In order to create this new projection you just need to go to Settings > Custom Projections > click the green plus symbol and then at the bottom of the window give your project a name and then paste in your new projection information into the box. See below for what this looks like for my NZ projection.

Click OK to activate it

Once you've created a new projection you can just go back to Project > Properties > CRS and search for the new projection and use it. This is what the NZ one looks like, below.

This is not a map without New Zealand

I mentioned above that you can have a globe view like the above in a Print Layout with a different, flat projection in the main map. This is very easy. See below for an example where I have the globe view projection in the top left and a different projection with the same layers in the bottom of the image - in this case using the Equal Earth projection.


One Print Layout, two different projections

This is where you set the CRS for each map

I've put this together quickly so it's not very polished but see below for an example of the kind of thing you could do using this method - I quite like the globe locator inset, and it's also used by a good few news organisations, including the BBC. This used to be quite a lot of hassle in QGIS but now it's very easy and, I think, quite effective.

I've used Layer Effects to add a drop shadow to the globe

The only thing I should add is that in order to get the sea showing in the background here - rather than having the land floating on a blank canvas, I took the 1 degree graticule and converted it to a polygon layer via Vector > Geometry Tools > Lines to Polygons...

One last example below, with lots of cities, just for fun.

Cities are from Natural Earth as well

That's all for now. I hope you find this useful.