I've been playing with SparQL. The acronym stands for SPARQL Protocol and RDF Query Language. If you appreciate the wacky humour of the self referential acronym - then I think you will love SparQL.
I don't. Anything to do with with databases tends to leave me cold - but SparQL does have some very interesting concepts.
A background story will explain my motivation for my investigation.
Picture a fetid bordello in Milton Keynes. The elders of the MKBAG enclave are in session. We've raided an ISP and have a list of postcodes that will be served with BT's Fibre To The Premises trial.
There's a problem - people living at these postcodes don't know about the trial.
We decide to approach the civil parish councilors - they can make trial announcement in their propaganda leaflets.
The enclave's wise leader leans over to me, covering me with thick blue brown cigar smoke: "I want you to select all postcodes within MK that are on the FTTP trial, and then group them by parish."
"I want the list by tomorrow!" he demanded as he pressed a grubby USB memory stick in my hand. "That's got an Excel spreadsheet with all the parish details."
I was not going to use dubious data. Let's go for the golden source. In the UK that's the Ordinance Survey. They will list postcodes by parish.
I quickly discovered their SparQL query test page. (Copy the Sparql text below in to their testpage.)
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select distinct ?type
where
{
?a rdf:type ?type .
}
limit 100
This tells me what the data store contains - such as http://data.ordnancesurvey.co.uk/ontology/admingeo/CivilParish
I snoop...
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select *
where
{
?civilparish a <http://data.ordnancesurvey.co.uk/ontology/admingeo/CivilParish>.
}
limit 10
One of the returned rows is http://data.ordnancesurvey.co.uk/id/7000000000000611 the parish of "Wick and Abson."
This record give me an "extent" which is a series of boundary points in OSGB coordinates.
I discover that wards can be easily found if you have a postcode:
Follow this link for my post code: http://data.ordnancesurvey.co.uk/id/postcodeunit/MK109HG and you'll reach the ward: http://data.ordnancesurvey.co.uk/doc/7000000000041910.
(I'm sure there's another dataset that will yield the ward councilors' names.)
But the problem is civil parishes are not part of the postcode result.
Given the urgency I have, I'll construct a query that gets all the parish boundaries in Milton Keynes. I master some C# code that will "IsPointInPolygon".
I'm sure there is a way to do this using SparQL - probably by hosting my own web server with an IsPointInPolygon implementation. (I put this down to the OS's penchant for OSGB co-ordinates, not lat longs.)
I request all the parish names and parish boundaries for the district (Milton Keynes) where I live (MK10 9HG).
http://www.pezholio.co.uk/2010/07/further-adventures-in-sparql/
http://blog.whatclinic.com/tag/ontologies
http://answers.semanticweb.com/questions/2042/how-to-represent-ordnance-survey-national-grid-reference-system-locations-in-rdf-and-convert-between-wgs84-and-osgb36
http://beta.kasabi.com/dataset/ordnance-survey-linked-data/apis/2rb
http://www.w3.org/2011/02/GeoSPARQL.pdf
http://os.services.tso.co.uk/geo/api
Get my head around...
PREFIX spatialrelations: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/>
Page last updated 24th August 2011
nick@anotherurl.com