Tuesday, March 8, 2016

Downloading GeoJSON boundaries using SPARQL from publicly available data

Leave a Comment

I'm interested in downloading some boundary files from statistics.gov.scot, which is an official statistical repository for sharing statistical data that utilises SPARQL queries.

Background

Statistics.gov.scot provides access to GeoJSON boundaries for number of administrative and statistical geographies, like local authority administrative boundaries or health boards. In my particular case I'm interested in download a data set with GeoJSON boundaries pertaining to data zones. Data zones are statistical geographies developed for the purpose of disseminating life outcomes data on a small area level. When accessed via the statistics.gov.scot sample data zone looks like that:

Sample data zone

The geography and the related data can be accessed here. The corresponding GeoJSON data is available here.

Problem

Data zones are available in two iterations, on produced in 2004 and another one updated recently. I would like to download first iteration produced in 2004. Following the information on the statistical entities, I drafted the following query:

PREFIX entity: <http://statistics.data.gov.uk/def/statistical-entity#> PREFIX boundaries: <http://statistics.gov.scot/boundaries/>  SELECT ?boundary      WHERE {         entity:introduced <http://reference.data.gov.uk/id/day/2004-02-01>   }  LIMIT 1000 

which returns the following error message:

Error There was a syntax error in your query: Encountered " "}" "} "" at line 7, column 3. Was expecting one of: <IRIref> ... <PNAME_NS> ... <PNAME_LN> ... <BLANK_NODE_LABEL> ... <VAR1> ... <VAR2> ... "true" ... "false" ... <INTEGER> ... <DECIMAL> ... <DOUBLE> ... <INTEGER_POSITIVE> ... <DECIMAL_POSITIVE> ... <DOUBLE_POSITIVE> ... <INTEGER_NEGATIVE> ... <DECIMAL_NEGATIVE> ... <DOUBLE_NEGATIVE> ... <STRING_LITERAL1> ... <STRING_LITERAL2> ... <STRING_LITERAL_LONG1> ... <STRING_LITERAL_LONG2> ... "(" ... <NIL> ... "[" ... <ANON> ... "+" ... "*" ... "/" ... "|" ... "?" ... 

when tested via the endpoint: http://statistics.gov.scot/sparql.

Comments

Ideally, I would like to develop other queries that would enable me to source other statistical geographies by using the entity: prefix. This should be possible as the entity: will contain information on the available geographies (name, acronym, date of creation).


The query:

PREFIX entity: <http://statistics.data.gov.uk/def/statistical-entity#> PREFIX boundaries: <http://statistics.gov.scot/boundaries/>  SELECT DISTINCT ?boundary ?shape WHERE {   ?shape entity:firstcode ?boundary }  LIMIT 1000 

Got me to something that looks like a list of desired geographies but I'm struggling to source the GeoJSON boundaries.

1 Answers

Answers 1

The first query is missing the subject. A SPARQL query defines a set of triple patterns - a subject, predicate, and object - to match an RDF graph. To turn your WHERE clause into a SPARQL triple pattern, try:

?boundary entity:introduced <http://reference.data.gov.uk/id/day/2004-02-01> 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment