First we find the geographical centre of each country. Since some countries include islands and territories that are a long way from their main landmass, these were excluded to make the centre more meaningful. We then measure the distance between the capital city and that centre.
We can't just compare those distances, as that would just make small countries come out on top. Instead we take the area of the country landmass, and divide the distance by that. Well, actually we divide it by the square root of the area, due to maths.
This means we now have the distance proportionate to the country size, which we can compare between countries.
Some countries on the map look like they should do much worse in the ranking than they currently do - Canada for instance. This is because the map is based on the Mercator projection, which hugely distorts the size of things the further away from the equator we go.
All calculations done were based on an edited version of the most detailed world polygon file I could find: the US State Department's Global LSIB. The LSIB generally places geographically distinct autonomous or dependent regions in separate polygon groups to those of their associated country - so many of these regions have not been included in calculations. An example of this is the Isle of Man, a British dependency between England and Northern Ireland.
I used Natural Earth data for cities, also with a few edits here and there. It would be more robust to use polygons covering the extent of the city, but this data is not available with global coverage. The modern 'city states' of Monaco, Singapore, Vatican City were removed; there was no way to measure their centrality given their entire landmass is one city.
In order to establish which polygons would be included in each country feature, a 300km geodesic buffer was drawn around each individual polygon in ArcMap. Geodesic essentially means that the buffer is drawn as if on the surface of a sphere, so distances are more accurate. Non-geodesic buffering would produce buffers that varied wildly in size according to the projection used.
An r script was then run on the data. Starting from the polygon containing the country's capital, overlapping buffers were merged together. Any not connected to the starting polygon at the end of this process were discarded, though some manual fixes were made. This process is why, for instance, Greenland is not part of the Denmark country polygon.
The r script also calculated the geodesic distances between capitals and centre points, along with the combined area of the selected polygons for each country. In order to be able to compare distances in proportion to the size of the country, they were divided by the square root of the country area. The resulting figure itself has not been included in the map environment, but instead has been converted into rankings.
All data was then tidied as necessary in QGIS. The very useful mapshaper tool was used to simplify and shrink the file size of the large LSIB file to something more practical for a web map: from 157mb to 2.3. Some smaller landmass polygons were lost in this process. The data calculated in r based on the full LSIB was joined to this simplified version, and numbers formatted for use in labels and text.
Geojson files of country polygons, capital cities, geographic centre points and the distance line between them were then loaded into the web map, which is built in Leaflet. Since the colour scheme chosen is aggressively impractical for those with colour blindness, a CSS-altering menu option was included.
Thanks for visiting. This was just a fun project to practice with leaflet and r. You can find my other work and projects here.