Finding and mapping the center of your world(ish)

Finding and mapping the center of your world(ish)

This is the center of Preston.

I made that discovery as I pondered a post I saw a little while ago.

The article came from The Londonist, who ran an experiment to find the center or London.  It was a repeat of an experiment they did in 2010, things were a bit make do and mend…

We pasted a map of Greater London onto cardboard, cut out the map, and then tried to balance it on a pin-head. The balance point, also known as the centre of gravity, can be said to be the geometric centre of London. 

But for the update they went a bit more high tech.

Step forward Tom Hoban, who’s now refined the method and thinks he’s found the centre of London to much greater precision. Rather than using cardboard and scissors, Tom traced an electronic map in AutoCAD software. He was then able to find the shape’s centre of gravity digitally, removing the imprecision of our balancing-on-a-pin malarky.

I thought the ‘malarky’ of the pin and card was really nice.  Very hands on. But it got me thinking about how easy it would be to work that out for other places.  (that’s how my brain works)

Find the shape

The first challenge is finding the ‘shapes’ of a city to work with.  In these days of data journalism anddigital mapping, I wondered if that kind of ‘data’ existed and it does; kind of. There are plenty of data sets that offer shape files; the data needed to ‘draw’ the shape of a city or (more commonly) electoral ward, county or country.  You see these a lot in visualizations of data like voting records etc. So it was just a case of finding one with about the right detail I needed.

The Office of National statistics maintains quite a nice list of  files with boundary information, which have that data included.  I chose  the Boundaries : County_and_unitary_authorities_(E+W)2013_Boundaries(Full_Extent).zip file.

Find the centroid!

As you expect these shapes are not uniform, they are polygons, so it took me a bit of Google work to find that the ‘center of gravity’ of  a polygon is called it’s centroid.

In mathematics and physics, the centroid or geometric center of a two-dimensional region is, informally, the point at which a cardboard cut-out of the region could be perfectly balanced on the tip of a pencil, assuming uniform density and a uniform gravitational field.

So it was a bit of piecing together.  I know you could easily map shape files using Google tools like Google Fusion tables etc. and I know that you can do some clever maths using scripting so the next step was to put it all together with more Google around ‘calculate the centroid of a polygon in Google maps‘.  Which, by a country mile,  is the most technical and intelligent sounding thing I’ve googled in the last 10 year.

Some time later…

Cutting a long Google very short, I ended up recognizing that doing it with Google maps was going to be hard – at least beyond my skills.  But my searching revealed that there was some good mapping software or GIS  available that might do the job. What’s that then

A geographic information system (GIS) lets us visualize, question, analyze, interpret, and understand data to reveal relationships, patterns, and trends.

I ended up using QGIS, an open source mapping program that works on PC and Mac.  I won’t lie, it’s a bit of bind to set up.  But once it’s done you have a pretty powerful set of tools and one that would be worth a look  for people doing a lot of mapping .

What’s great about QGIS is that once the ‘polygons’ are loaded in, it has a very neat menu item that calculates the centroids. Instant centers of all the areas on the map in one click!

Here’s a quick how-to:

This is shape file

This is shape file

Download and unzip the mapping data. If you look in the unzipped folder you’ll see a file with a .shp extension. That’s the one we want.

  • Open QGIS

QGIS_2_2_0-Valmiera_and_Applications

  • Click the Add Vector Layer button or pick Layer > Add Vector layer from the menu
  • Browser to the shape file (.shp) from the unzipped folder and open
  • A nice rendering of the shape file appears similar to the one below.

Don't worry if your colours are different. It's random

Don’t worry if your colours are different. It’s random

Contains National Statistics data © Crown copyright and database right 2013

  • Make sure the layer you have created is selected and the select Vector > Geometry Tools > Polygon Centroids

Vector

The system offers a dialouge box. It wants to save the data as a new file. I saved mine in a new folder called centroids but you can put it where you like.  Make sure you check the Add Results to Canvas option or you won’t see the centers.  The result is something like:

![Untitled1](https://i0.wp.com/res.cloudinary.com/digidickinson/image/upload/v1524223175/Untitled1_qacyh5.jpg]
Contains National Statistics data © Crown copyright and database right 2013

That’s all the centroids calculated and plotted.

Getting the data on to a google map

For a number of reasons I wanted to make sure I could share the results on a google map.  One of the easier ways to to get any complex location data into a google map is to use Google Fusion tables. They play nicely with location information saved as a KML (Keyhole markup language) file.

QGIS makes short work of this.

  • Select the new layer with your centroids in
  • Select Layer > Save As
  • Pick  Keyhole markup language KML from the Format option
  • Select a location and filename to save the content. Make sure you keep the .kml extension.
  • Repeat the process with the original layer (with the local authority areas on it)

The process to get the files in to Google Fusion tables is pretty easy. Here’s a slightly amended version of what Google suggests:

  1. Go to Google Docs. Sign in to your Google Account or create a Google Account if you don’t already have one. (Note that you while can use a Google Apps for your Domain account for Fusion Tables, you will not be able to create maps.)
  2. Click the “Create” button.
  3. Click the “Connect more apps” bar at the bottom of the resulting list.
  4. Type “fusion tables” in the “Search Apps” box and hit the “Enter” key.
  5. Click the blue “+ CONNECT” button, then click the “OK” button in the confirmation dialog box.
  6. Click “Create > Fusion Table (experimental)”.
  7. In the Import new table dialog box, click “Choose File”.
  8. Find the KML file you created from  QGIS
  9. Check that the data is formatted correctly and click “Next”.
  10. Give your table a name and click “Finish”.

Once it’s imported you can click the Map tab and you’ll see the elements mapped (either the outlines of the areas or the dots that represent the centroids.

You can embed the map straight from google fusion tables like this

Or you could use something like the Google Fusion Maps Wizard to mix together layers into one map. Like this:

Once you have it on a map you can also take advantage of the satellite view and the Street view tool on google maps to get a good look at the center of your world.

Conclusions

This may all feel like a sledgehammer to crack a pointless nut! I guess it is. It’s a bit of fun that spiralled. The best I could say is that it falls in to my find a tool that answers a question methodology.  But here’s some observations and what I learned  along the way:

  • The center really does depend on the boundaries you pick. The picture at the start of this post is based on the Urban Audit of Greater cities boundaries for Preston (data). That’s different from the center that the Unitary and Borough boundaries throws up. (that’s in a field just near the M55 junction on the M6)
  • Picking the The Full Extent version of the files does skew things a little as it describes the shape of an area even if some of it stretches into the sea! So the methodology isn’t rock solid on a number of counts
  • There are lots of data sets to play with. Qgis means you could load loads up and compare.
  • Using QGIS ties you to the desktop – not great if you’re in newsroom with locked-down IT.
  • Using QGIS opened my eyes to the power of GIS software in general and how it could be part of a data journalist’s toolkit. But if you’re doing a lot of data mapping (rather than mapping) I do think something like Tableau is the better place to focus your time.

Finally, and most importantly I’m bound to repeat that all of this post contains National Statistics data © Crown copyright and database right 2013

Subscribe to andydickinson.net

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe