You are here: Home > May 2006 > Friday 12 > SPARQL Geo Extensions

May 12, 2006

SPARQL Geo Extensions

I've been experimenting with some ARQ Extensions for manipulating geographical information in SPARQL.

I've implemented three functions which are now running on this server, to use them you'll need to add the following PREFIX to your queries:


PREFIX myfn: <java:com.ldodds.sparql.>

You're free to change the name of the PREFIX, but the URI must be the above for now. WARNING: the URI is likely to change, initially to a proper URI for the collection of geo extensions. Hopefully eventually to a formally specified URI if I can drum up interest amongst SPARQL developers to implement the extensions on other engines. So use with care now and check bac for updates.

With that PREFIX declared you can now use the following three functions:


myfn:Distance(?a, ?b)

The Distance function will return the distance between two points in kilometres. It assumes that the variables its passed conform to the examples given on the GeoRSS in RDF docs. The literal values are automatically split to get the latitude and longitude. Here's an example query.

A better option for data that uses the Geo vocab such as this data mapping a walk through Bristol is to use the following function:


myfn:Distance(?lat1, ?lon1, ?lat2, ?lon2)

Here's an example query.

The final function allows a query to test whether an arbitrary point is within a bounding box:


myfn:PointInBoundingBox(?minlat, ?minlon, ?maxlat, ?maxlon, ?lat, ?long)

The first four parameters define the southwest and northeast corners of the bounding box. The last two define the point to test.

There's an example query.

Let me know if you come up with any interesting hacks, or whether you think the math is wrong!

« Applying XSLT to SPARQL Results | Main | Experimenting with EmbeddedRDF and GRDDL Support »