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.
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.
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.
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:
2. Polygon-definitions for 0.1-degree lat-long ‘square’ tiles, with urls such as:
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.
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)
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.