Mapping the English Deprivation Stats: Part 2 - Querying the data
This article the 2nd in a series, where we’re building a Linked Data application to map the English Indices of Multiple Deprivation Stats. The final source code for the app can be found on github. If you missed the first part, you can find it here.
Note: These articles use Github gists for showing code-snippets, and if you’re viewing this in a feed reader they might not show up. So I recommend you read it on the web instead.
Last time…
In the last instalment, we got the basic page and code structure set up. In this article we’ll explore how the deprivation data is stored, write some SPARQL to query it, and draw a Google map.
Score Data
The score data is available as Linked Data in a variety of datasets: one for each deprivation domain (i.e. housing, crime etc), plus a dataset of combined scores. All of the data in these datasets is accessible through a SPARQL endpoint.
PublishMyData, the platform on which this Linked Data is hosted, caches the results of commonly executed SPARQL queries (and will therefore respond more quickly to common queries). This means that by making our app only make a relatively small number of distinct different queries against the server, we can ensure better performance. We should bear this in mind for later.
Boundary Data
The boundaries of the LSOAs are available as GeoJSON in two forms from the OpenDataCommunities.org server:
1. Individual polygon definitions with urls such as:
http://opendatacommunities.org/lsoa_boundaries/E01017190.json
2. Polygon-definitions for 0.1-degree lat-long ‘square’ tiles, with urls such as:
http://opendatacommunities.org/lsoa_tiles/lat53.4/long-2.3.json
Getting the data
There are over 32,000 LSOAs in England, and 8 different indicators of deprivation, which makes a total of over a quarter of a million observations (like this one). So, it wouldn’t make sense to just download all the data to the browser: we only want to get the data relevant to the portion of the map currently being viewed. Let’s do this via a SPARQL query.
Aside: Various other visualisations have been made using Google Fusion tables to map deprivation in England (such as this one by the Guardian). Google Fusion tables are neat because they allow you to quickly augment a Google map with data, but they limit what kind interaction you can build into the map. I want to be able to add custom JavaScript interactivity to the LSOA polygons on my map.
The following query will get all the LSOAs along with their scores and lat/long centroids within a certain bounded area:
(You can see the results of this query, and experiment with the SPARQL, here)
Bearing in mind what I said earlier about how the caching works for SPARQL queries on our server, let’s make our JavaScript code generate queries like that, which get the data for a 0.1×0.1 degree tile. There are roughly 2000 of these tiles which cover the country, so we’re fairly likely to get a cache hit once people start playing with the app …and handily it matches up nicely with how the LSOA boundary data is organised too!
Drawing the Map
Before we can do anything interesting, we’ll need a Google map object, so lets make one in our main closure (in the HTML page). The map will draw itself in the map_canvas element, and initialize its location to Manchester, where my office is (feel free to pick a different initial location if you like).
Refresh your browser, and you should see the map being rendered at your initial lat/long.

Next time…
In the next instalment we’ll add some JavaScript to generate the correct SPARQL query for the currently displayed area on the map, and hopefully get on to actually drawing the boundaries too.


