A colleague was asking me if I knew how to plot SPARQL query results from the Ordnance Survey linked data onto an OS OpenSpace map. Although I’d done it a few times before, it was never something I’d blogged. So here goes…
This is a lot easier than you might imagine. The first thing you want to do is perform your SPARQL query and get back the results as a csv file. I blogged about this a while back, but here is a quick recap. Let us suppose I want to plot a centroid for all the districts in England, and have their name appear in the pop up text. It is easy to perform a query to get back the easting, northing and name for all the districts. First go to the Boundary-Line(TM) SPARQL endpoint and enter the following query:
select ?x ?y ?name
?a <http://www.w3.org/2000/01/rdf-schema#label> ?name .
?a <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/easting> ?x .
?a <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/northing> ?y .
?a a <http://data.ordnancesurvey.co.uk/ontology/admingeo/District> .
Make sure the response format is set to CSV. Now click the query button. The “Reponse” box will have your query results, and the “Request box” should have a long complicated looking URL:
So far so easy.
osMap.setCenter(new OpenSpace.MapPoint(400000, 400000), 7);
osMap.setCenter(new OpenSpace.MapPoint(400000, 400000), 1);
so we are zoomed all the way out.
We now need to change the input text file. To do this change the following line in the sample code:
var markersFile = “/res/mymarkers.txt”;
In this line replace /res/mymarkers.txt with the URL you got from the SPARQL endpoint in the Request box. Once you have done that click the ‘render’ button and you should now see your results plotted on an OS OpenSpace map. Click on a map pointer to display the name of the district. Easy as that.
As an exercise to the reader…consult my last few blog posts and display markers for postcodes in a district of your choosing.