Last active
August 29, 2015 14:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!'); | |
}); | |
} | |
) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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