Skip to content

Instantly share code, notes, and snippets.

@hubgit hubgit/README.md
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.