Google Fusion Tables is great for creating interactive maps from a spreadsheet – but it isn’t too keen on easting and northing. That can be a problem as many government and local authority datasets use easting and northing to describe the geographical position of things – for example, speed cameras.
So you’ll need a way to convert easting and northing into something that Fusion Tables does like – such as latitude and longitude.
Here’s how I did it – quickly.
Find an API to do the work for you
The first thing I needed was an online tool that will do the conversions. Nearby.org.uk is pretty useful for doing so manually – and there’s an API as well – but I wanted something that would give me a nice JSON feed for Google Refine.
So I asked Twitter.
This is where being a part of communities of practice is important for journalists. (Samuel Johnson once said that there are two types of knowledge: “We know a subject ourselves, or we know where we can find information upon it.” Those communities are an example of the latter).
Using Google Refine to work with the API
The API works by generating information in JSON format based on a URL (I explain JSON in this post).
For example, the following URL generates a page of JSON with the latitude and longitude for easting 492412, northing 329757:
I know that Google Refine will be able to use that JSON to extract the latitude and longitude for dozens of rows with different values and add them to the spreadsheet (here’s a post explaining that in more detail).
So here’s what I do:
Generating the end bit of the URLs
I need a new column in my spreadsheet that fetches information from those URLs – there are a couple of ways of doing this but I’m going to show the simplest way for a beginner (rather than the simplest method programmatically*)
This involves creating a new column which conveniently puts together the end part of the URL that I’ll be calling: in this case easting=492412&northing=329757 (where the numbers change in each cell).
- Click on the drop-down arrow at the top of the Easting column and select Edit column > Add column based on this column…
- In the window that appears type the following GREL (Google Refine Expression Language): “easting=”+cells[“Easting”].value+”&northing=”+cells[“Northing”].value
- This assumes that the column with the easting values is called ‘Easting’ (note the capital E) and the northing column is called ‘Northing’. Change these to the names of your columns if they’re different.
- Give the new column a name in the box at the top and save it. You should see a new column appear, populated with values like easting=492412&northing=329757 – in each cell the process is simply writing a string of characters that begins with easting=, then adds the value in the cell within the ‘Easting’ column, adds &northing=, then adds the value in the cell within the ‘Northing’ column.
These are the second parts of the URLs we’re going to fetch lat-long values from.
Fetching data from those URLs
At the top of this new column, then:
- Click on the drop-down arrow of your newest column and select Edit column > Add column by fetching URLs…
- In the window that appears type the following GREL (Google Refine Expression Language): “http://www.uk-postcodes.com/eastingnorthing.php?”+value
- As you can see, this simply looks at a URL that begins http://www.uk-postcodes.com/eastingnorthing.php? and ends with the value in each cell of the column selected. It will then populate a new column of cells with the JSON returned by each different URL.
- Give the new column a name in the box at the top and save it. You should again see a new column appear – but this will take longer, because it is going to that website and gathering information. Make a cup of tea.
Extracting the latitude and longitude into separate cells
Great – now we have the lat-long values for each row. But to visualise this data we need separate columns for latitude and longitude, so this is how we get that out of the JSON. UPDATE: In the 2.0 version of Refine the old GREL (struck through below) no longer seems to work – thanks to Tom in the comments for pointing this out and adding the new code which is shown below.
- Click on the drop-down arrow and select Edit column > Add column based on this column…
- In the window that appears type the following GREL (Google Refine Expression Language):
- This will look at the value of each cell, and pull out the bit after “lng” and populate a new column of cells with each value
- Give the new column a name in the box at the top (e.g. longitude) and save it.
- Repeat the process for latitude – the GREL you need is
You should now have a spreadsheet of data that includes latitude and longitude for each row. Click on Export in the upper right corner and select Comma-separated value.
Visualise it in Fusion Tables
Go to Google Fusion Tables and upload that file. Then open it. Click on Visualize and you should have a map option. Once visualised you can embed it elsewhere by clicking on Get embeddable link.
*The simpler way programmatically is to go straight to ‘Fetching data from URLs’ and use the following GREL code: