Generating Google Earth Overlays with SPARQL and XSLT

Here’s some notes on some hacking I’ve been doing over the last few days.
Firstly, I’ve implemented some extensions for manipulating geo data in SPARQL queries. There’s a write-up on the XMLArmyKnife blog.
That allows you to ask questions such as “find points 10 kms from this location” and “test whether a point is within a bounding box”.
Secondly, I’ve also been exploring options for manipulating the results of SPARQL SELECT queries using XSLT. I’ve updated mortenf’s SPARQL to RSS stylesheet, so you can now generate RSS 1.0 from appropriately “shaped” SELECT queries.
I’ve also implemented a stylesheet to convert SPARQL results into a Google Earth KML file. To use it you’ll need to ensure that your SELECT query returns four variables: title, description, lat, long. These form the title, description and co-ords of a series of Placemarks in the generated KML file. Actually only the latitude and longitude are required, but the view will be pretty uninteresting without some titles.
The Placemarks are gathered into a folder. To configure a name and description for the folder you can pass in two stylesheet parameters, folder-name and folder-desc. As noted you can just add these to the query string of an XML Army Knife SPARQL Service query.
If you do use the XAK query, then the Content-Type of the response is automatically configured based on the media type set in the stylesheet, so you should find Google Earth automatically launches if its configured to do so in your browser.
Pulling all that together, here’s a SPARQL query that lists Museums in London. Or at least, museums known to The Open Guide to London which happens to have an RDF view of its data. And here’s the results in the SPARQL Results XML format.
Combining that with the SPARQL to KML stylesheet, here’s a dynamically generated KML layer that shows Museums in London.
If you use the “Add Network Link” option in Google Earth you can manually add the URL and configure the refresh parameters, e.g. once every 48 hours. That way your Google Earth installation will periodically pick up any new data added to the London OpenGuide.
Its very easy to come up with alternate queries that generate other results, especially if you use the geo extensions, which would allow you to ask for museums (or other places) within a few kilometres of where you’re staying or visiting.
Have fun!