OntoWiki dealing with OS postcodeunit - DigitalCommons/open-data-and-maps GitHub Wiki

How to deal with Ordnance Survey postcodeunit in OntoWiki

There are some alternative approaches. At the time of writing, we are creating triples to load into OntoWiki (Alternative 2, below).

Reference docs

Alternative 1: Get lat/long for os postcodeunit via OS SPARQL endpoint

Note that OS has a SPARQL endpoint at http://data.ordnancesurvey.co.uk/datasets/os-linked-data/explorer/sparql The following query made at that SPARQL endpoint produces results:

SELECT ?postcode ?easting ?northing ?lat ?long
WHERE {
?postcode <http://www.w3.org/2000/01/rdf-schema#label> "SO16 0AS".
?postcode <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/easting> ?easting.
?postcode <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/northing> ?northing.
?postcode <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat .
?postcode <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?long .
}
LIMIT 20
OFFSET 0

Result:

<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
  <head>
    <variable name="postcode"/>
    <variable name="easting"/>
    <variable name="northing"/>
    <variable name="lat"/>
    <variable name="long"/>
  </head>
  <results>
    <result>
      <binding name="postcode">
        <uri>http://data.ordnancesurvey.co.uk/id/postcodeunit/SO160AS</uri>
      </binding>
      <binding name="easting">
        <literal datatype="http://www.w3.org/2001/XMLSchema#decimal">437318.00</literal>
      </binding>
      <binding name="northing">
        <literal datatype="http://www.w3.org/2001/XMLSchema#decimal">115539.00</literal>
      </binding>
      <binding name="lat">
        <literal datatype="http://www.w3.org/2001/XMLSchema#decimal">50.938094</literal>
      </binding>
      <binding name="long">
        <literal datatype="http://www.w3.org/2001/XMLSchema#decimal">-1.470267</literal>
      </binding>
    </result>
  </results>
</sparql>

Federated queries

See

The problem with using SERVICE is that we still need to cache data both for performance, and possibly to prevent abuse of the OS SPARQL endpoint.

There are some examples of federated SPARQL queries on the public-lod mail archive.

Alternative 2: Load lat/long data from os postcodeunit into our OntoWiki

Note that the function map_app_json in generate-triples.rb already performs a RDF::Query on the postcodeunit, and caches the result in os_postcode_cache.json. So we have in JSON the data needed to create RDF triples of the form

<http://data.ordnancesurvey.co.uk/doc/postcodeunit/SO160AS> <http://www.w3.org/2003/01/geo/wgs84_pos#lat> 50.938094^^<http://www.w3.org/2001/XMLSchema#decimal>
<http://data.ordnancesurvey.co.uk/doc/postcodeunit/SO160AS> <http://www.w3.org/2003/01/geo/wgs84_pos#llong> -1.470267^^<http://www.w3.org/2001/XMLSchema#decimal>

So, we could produce a file for upload into OntoWiki with the lat/long data for each postcode that we need.

Alternative 3: Use Virtuoso Sponger

Tim Davies' email of 2016-08-08 has the following advice:

"The underlying Virtuoso triple store has a mode where, at query time, it will fetch (and I think cache) external references. I think the documentation here may help http://virtuoso.openlinksw.com/dataspace/doc/dav/wiki/Main/VirtSpongerLinkedDataHooksIntoSPARQL but I'll admit Virtuoso documentation is far from accessible - and it usually takes me a bit of digging to work this out."

In /var/www/html/OntoWiki/config.ini there are a bunch of parameters for cache.backend and cache.frontend. These need investigation, just in case they are what we need.

Needs investigation.

⚠️ **GitHub.com Fallback** ⚠️