Skip to content

Instantly share code, notes, and snippets.

@hubgit
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hubgit/a06dc1ddceba20290584 to your computer and use it in GitHub Desktop.
Save hubgit/a06dc1ddceba20290584 to your computer and use it in GitHub Desktop.
Query the Boundary Line SPARQL API to get names, GSS codes and Unit IDs for each Westminster constituency
var fs = require('fs');
var request = require('request');
fs.readFile('query.sparql', 'utf8', function(err, data) {
if (err) throw err;
request.post(
'http://data.ordnancesurvey.co.uk/datasets/boundary-line/apis/sparql',
{
form: {
query: data,
output: 'csv',
}
},
function (err, response, body) {
if (err) throw err;
if (response.statusCode !== 200) {
throw 'Error:' + response.statusCode;
}
fs.writeFile('constituencies.csv', body, function (err) {
if (err) throw err;
console.log('Saved!');
});
}
)
});
select ?name ?regionName ?gss ?unit_id
where
{
?x a <http://data.ordnancesurvey.co.uk/ontology/admingeo/WestminsterConstituency> ;
<http://www.w3.org/2000/01/rdf-schema#label> ?name ;
<http://data.ordnancesurvey.co.uk/ontology/admingeo/gssCode> ?gss ;
<http://data.ordnancesurvey.co.uk/ontology/admingeo/inEuropeanRegion> ?region ;
<http://data.ordnancesurvey.co.uk/ontology/admingeo/hasUnitID> ?unit_id .
?region <http://www.w3.org/2000/01/rdf-schema#label> ?regionName .
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment