Search

XQuery mapping of OpenStreetMap data

Over on the data.gov.uk developers group on Google, Melvin Carvalho had been playing  with the OpenStreetMap interface LinkedGeoData.  This project provides a custom REST API which returns text/rdf+n3 format triples. 

Pubs within 1 km of my home:  http://linkedgeodata.org/triplify/near/51.4769,-2.5886/1000/amenity=pub



<http://linkedgeodata.org/triplify/node/26159351#id> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://linkedgeodata.org/vocabulary#node> .
<http://linkedgeodata.org/triplify/node/26159351#id> <http://www.w3.org/2003/01/geo/wgs84_pos#long> "-2.5894"^^<http://www.w3.org/2001/XMLSchema#decimal> .
<http://linkedgeodata.org/triplify/node/26159351#id> <http://www.w3.org/2003/01/geo/wgs84_pos#lat> "51.4798"^^<http://www.w3.org/2001/XMLSchema#decimal> .
<http://linkedgeodata.org/triplify/node/26159351#id> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://linkedgeodata.org/vocabulary#pub> .
<http://linkedgeodata.org/triplify/node/26159351#id> <http://linkedgeodata.org/vocabulary#distance> "330" .
<http://linkedgeodata.org/triplify/node/26159351#id> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://linkedgeodata.org/vocabulary#node> .
<http://linkedgeodata.org/triplify/node/26159351#id> <http://linkedgeodata.org/vocabulary#created_by> "Potlatch 0.5d" .
<http://linkedgeodata.org/triplify/node/26159351#id> <http://linkedgeodata.org/vocabulary#name> "The Golden Lion" .

The return needs to be parsed to XML to be useful in XML tools. I wrote a simple parser in XQuery using the eXist httpclient module to convert to a basic XML structure which grouped the triples by subject and then property within subject with multiple values:



<subject about="http://linkedgeodata.org/triplify/node/26159351#id">
        <property predicate="http://www.w3.org/1999/02/22-rdf-syntax-ns#type">
            <value>http://linkedgeodata.org/vocabulary#node</value>
            <value>http://linkedgeodata.org/vocabulary#pub</value>
            <value>http://linkedgeodata.org/vocabulary#node</value>
        </property>
        <property predicate="http://www.w3.org/2003/01/geo/wgs84_pos#long">
            <value type="http://www.w3.org/2001/XMLSchema#decimal">-2.5894</value>
        </property>
        <property predicate="http://www.w3.org/2003/01/geo/wgs84_pos#lat">
            <value type="http://www.w3.org/2001/XMLSchema#decimal">51.4798</value>
        </property>
        <property predicate="http://linkedgeodata.org/vocabulary#distance">
            <value type="http://www.w3.org/2001/XMLSchema#string">311</value>
        </property>
        <property predicate="http://linkedgeodata.org/vocabulary#created_by">
            <value type="http://www.w3.org/2001/XMLSchema#string">Potlatch 0.5d</value>
        </property>
        <property predicate="http://linkedgeodata.org/vocabulary#name">
            <value type="http://www.w3.org/2001/XMLSchema#string">The Golden Lion</value>
        </property>
    </subject>


Then I can transform this XML to kml using XSLT.  The sequence of transformations is run in a pipe:

KML  Edit Pipe

Finally this pipe is wrapped in a simple Interface which uses CloudMade to render the maps.

Later

Melvin pointed me at the Google Group for Linked Geo Data where I now see there is a SPARQL interface.  The LinkedGeoData project has a very neat browser  but my aim is to experiment with XML technologies to do data mashups - I think the  component-based approach is beneficial here - and required only a couple of hours to build, mostly on hacking the basic N3 parser

How can I view n3xml.xq? It'd be interesting to put a function to parse text/rdf+n3 in #expath. (@fgeorges)
Hi John, it's a bit of a hack - I've treated newlines as significant but I don't think that's right, its only been tested on the LinkedGeoData - and the XML structure is just one to suit me. Anyway for what it's worth the source code is

http://www.cems.uwe.ac.uk/xmlwiki/util/n3xml.txt