Archive

Posts Tagged ‘opendata’

Announcing new beta Ordnance Survey Linked Data Site

April 25, 2013 1 comment

Ordnance Survey has released a new beta linked data site. You can read the official press release here.

I thought I’d write a quick (unofficial) guide to some of the changes. The most obvious one that is hopefully apparent as you navigate round the site is the much improved look and feel of the site. Including maps (!) showing where particular resources are located. Try this and this for example. Maps can be viewed at different levels of zoom.

Another improvement is the addition of new APIs. The first of these is an improved search function. Supported fields for search and some examples can be found here. The search API now includes a spatial search element.

The SPARQL API is improved. Output is now available in additional formats (such as CSV) as well as the usual SPARQL-XML and SPARQL-JSON. Example SPARQL queries are also included to get users started.

Another interesting addition is a new reconciliation API. This allows developers to use the Ordnance Survey linked data with the Open Refine tool. This would allow a user to match a list of postcodes or place names in a spreadsheet to URIs in the Ordnance Survey linked data.

In the new release the Ordnance Survey linked data has been split into distinct datasets. You could use the above described APIs with the complete dataset or, if preferred, just work on the Code-Point Open or Boundary Line datasets.

For details on where to send feedback on the new site please see the official press release here.

Update: I blogged a bit more about some of the new APIs here.

Making things with Ordnance Survey Linked Data…

November 3, 2011 7 comments

Following the example of “Making things with BBC data” I thought I’d ask the same question for Ordnance Survey linked data. Please leave a comment if you’ve used Ordnance Survey linked data for anything from a quick hack, full blown project or if you even just link to it in your data. Thanks!

 

 

Adventures with Kasabi…and a request for help…

October 5, 2011 1 comment

I’ve been playing around with Kasabi a bit of late. Kasabi is a new information market place from Talis that provides a useful place to publish your data, and then build services on top of it.

By way of a quick example you’ll see that the currently Ordnance Survey Linked Data is hosted in Kasabi here. There are a number of standard APIs provided with each dataset such as a SPARQL endpoint, search API etc. Kasabi provides an easy way to map complex SPARQL queries to simple API queries. For example, this API provides an easy way to do topological queries on the Ordnance Survey Linked Data. For example:

http://api.kasabi.com/dataset/ordnance-survey-linked-data/apis/33m?id=7000000000037256&spatialrelation=touches&apikey=yourkey

will find all regions that touch The City of Southampton.

This API gives you a list of all postcodes (and their lat/long) within a particular region. For example:

http://api.kasabi.com/api/ordnance-survey-postcode-region?district=7000000000037256&apikey=yourkey

will find all postcodes inThe City of Southampton. Additionally we can apply a style sheet to get back the same information as KML:

http://api.kasabi.com/api/ordnance-survey-postcode-region?district=7000000000037256&apikey=yourkey&output=kml

Kasabi also provides a handy place to store and host data, and one Sunday afternoon I decided to see how easy it would be to create a couple of hyperlocal datasets: one for Southampton and one for Hampshire. The basic approach in creating these hyperlocal datasets was to effectively ‘cookie cut’ region specific data from a number of different linked (open) data sets and put them into one store. So for Southampton and Hampshire we have a list of: airports, bus stops, stations, schools, GPs, hospitals, renewable energy generators, heritage sites, councillors, crime statistics, administrative regions and postcodes…   Each important element, like schools or hospitals, is linked to a postcode, district, ward—and in the case of Hampshire—county. The Ordnance Survey linked data is effectively acting as the clue between disparate sources of information. The fact that each of these datasets was provided as linked data, and furthermore referenced common identifiers for administrative regions and postcodes, meant it was very easy to bring them together in one store. Some sample queries are provided here. It gets more interesting when you combine elements from different datasets to, for example, ask questions like ‘find me GPs in my ward, and all the bus stops within a 100 metre radius of those GPs’.  If one were extra paranoid it would then be possible to extend the query to only find bus stops in areas of low anti-social crime levels. These queries are all well and good, or ‘nerdy, but nice’ as Andrew Stott put it.

What I was really hoping to do was build a nice webapp on top of this integrated data. Anyone who has seen my previous mash-ups will know that web design is not amongst my key skills, so Zach Beauvais suggested I put word out to the developer community to see if anyone fancied building on this data to make something cool and interesting like (for example) the (in)famous postcode paper. Any volunteers? :)

 

 

 

So what can I do with the new Ordnance Survey Linked Data?

October 25, 2010 7 comments

In a previous post I wrote up some of the features of the new Ordnance Survey Linked Data. In this blog post I want to run through a concrete example of the sort of thing you can build using this linked data.

A while ago Talis built their BIS Explorer. The aim of this application was to allow users to “identify centres of excellence at the click of a button” and more can be read about the application here. This data mash-up took different data sources about funded research projects and joined them together using linked data. In the original application you could, for example, look at funded research projects by European Region in Great Britain. This can be seen here. At the time this demo was created Ordnance Survey was yet to publish its postcode data as linked data, but if they had it would have been very easy to get a more fine grained view of research projects down at the county and district level. Here’s how…

The basic data model of the original BIS data was fairly straight forward. Universities and businesses have a link to the projects they worked on. For each university there is also postcode information. Things get interesting if instead of/as well as linking to a string representation of a postcode you link to the URI for said postcode. This can be done by using the property:

http://data.ordnancesurvey.co.uk/ontology/postcode/postcode

So say we wanted to do this for Imperial College. All we need is this (this example is in N-Triple format) in our data:

<http://education.data.gov.uk/id/institution/ImperialCollegeOfScienceTechnologyAndMedicine>

<http://data.ordnancesurvey.co.uk/ontology/postcode/postcode>

<http://data.ordnancesurvey.co.uk/id/postcodeunit/W68RF> .

Now, by the power of linked data, connecting to a resource for the postcode means we can now enrich our university dataset with knowledge of the ward, county and district the university is in. Also, given that the university is connected to a project we have a link from project to region. Through the link from project to university to postcode to region we can now start to have a more finely grained view on which areas are getting more funding.

So how do we do this in practice? There are the steps I followed.

  1. Download the BIS data from here and load it into a triple store (linked data database) of your choice. There are plenty of good open source ones available e.g. Sesame or TDB to name two.
  2. I then then added the links to postcode URIs as described above.
  3. Following that I loaded the data for the postcodes in a similar manner to that described here. A relatively simple script retrieved the RDF for the relevant postcodes and loaded the RDF into my store. The nice thing about linked data and RDF is that the stores are like a big bucket of data and you can keep throwing more and more in. Hopefully future linked data tools will make this step trivial, but for now some scripting was required.
  4. Job done. I now have links from research projects to regions.

Basically what I created from this was an aggregation of various datasets that you can now query. This is something that is made very easy using linked data and URIs to identify things like postcodes. As more publishers release data in linked data form there is more and more potential for building services and applications on top of aggregations of these datasets.  So that’s what I decided to do…

This application (I make the usual apology for my lack of web development skills and for the slowness which some caching would not doubt sort out) builds a clickable map view of this data aggregation. The OS OpenSpace API makes it possible to retrieve the unit ID for selected polygons. I can then use this unit ID in a SPARQL query to find the projects funded in that region.

However, it would have been easier if there was a RESTful API on top of the data aggregation that would have let me retrieve these results instead of doing some SPARQL. So that is what I decided to build next using the Linked Data API. The linked data API basically lets you create RESTful type shortcuts to relatively complex SPARQL query. Due to my lack of PHP skills it was an initially bumpy ride getting it to work (see here) but I got there in the end and the result was an API that lets you return research projects by selecting regions either through their SNAC codes or Ordnance Survey IDs, e.g:

http://www.johngoodwin.me.uk/bis/api/project/county/os/{unit id},

e.g. http://www.johngoodwin.me.uk/bis/api/project/county/os/17765

 

results can be returned in different formats using content negotiation [1] or by simple adding the relevant .html, .json to the URI, e.g.:

http://www.johngoodwin.me.uk/bis/api/project/euro/os/41424.html

http://www.johngoodwin.me.uk/bis/api/project/euro/os/41424.json

I hope this example shows how linked data can be useful in building applications on top of data aggregations. To summarise:

  1. Publishers release data in linked data format.
  2. Having data in a common format (RDF) with dereferencable URIs makes it relatively each to retrieve and aggregate from a number of resources, especially if data is linked to URIs for ‘things’ and not just ‘strings’.
  3. The linked data API makes it possible to build a RESTful service on top of a data aggregation so web developers need not be put of by complex SPARQL queries.
  4. Applications can then built using these services.

[1] for some reason the HTML conneg only seems to work in Firefox.

/location /location /location – exploring Ordnance Survey Linked Data – Part 2

October 25, 2010 5 comments

Ordnance Survey have now released an update to their linked data, which can be seen here. The new data now includes postcode information as well as a few changes to the administrative geography data. In this post I’ll go through what’s in the data, and give a few sample SPARQL queries.

I spoke a bit about the administrative geography data in a previous blog post – but the data has changed a bit since then. Just to re-cap the administrative geography linked data contains information about administrative and voting geographic regions. These include unitary authorities, counties, wards, constituencies, Welsh Assembly regions and a whole lot more [1]. Here are some examples:

If you want to find a full list of the sorts of thing you can find in the data simply go to the query interface (or SPARQL endpoint as it is know) and try the following query:

select distinct ?type

where { ?a a ?type . }

Now you have the list all of type of things in the data you can as for lists of instances of those types.

For example, the following query will return all of the unitary authorities:

select ?a

where {

?a a <http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority&gt; .

}

All of the names of all the regions have now been modelled using the SKOS vocabulary. If you want to find the official names of all the unitary authorities you can simple issue a query like:

select ?a ?name

where

{

?a a <http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority> .

?a <http://www.w3.org/2004/02/skos/core#prefLabel&gt; ?name  .}

Also included in the data are two attributes called Unit ID and Area Code. These values are useful if you want to produce a mashup using this data and display it by boundary.

So for example, for Southampton (http://data.ordnancesurvey.co.uk/id/7000000000037256) the area code is UTA (for unitary authority) and the unit ID is 37256. These values can be used as follows:

/*here we set-up the our variable called ‘boundaryLayer’ with the strategies that we require. In this case, it is its ID and type i.e. Unitary Authority */

boundaryLayer = new OpenSpace.Layer.Boundary(“Boundaries”,

{ strategies: [new OpenSpace.Strategy.BBOX()], admin_unit_ids: ["37256"], area_code: ["UTA"] });

//then we add the bounadry to the map osMap.addLayer(boundaryLayer);

//this effectively refreshes the map, so that the boundary is visible

osMap.setCenter(osMap.getCenter());

to display the Southampton boundary using the OS OpenSpace API. See http://openspace.ordnancesurvey.co.uk/openspace/support.html for more details.

Arguably the most useful information in this data are the qualitative spatial relationships between different regions. Regions are related to the regions they contain, they are within and they touch. In the case of the touching relationship only regions of the same type have an explicit touching relationship. The exception to this are unitary authorities, counties, district and metropolitan district that also have touching relationships between each other. The following simple query will return a list of all counties, districts and unitary authorities that border The City of Southampton. It will also return their names:

PREFIX spatialrelations: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/&gt;

select ?a ?name

where

{

?a spatialrelations:touches <http://data.ordnancesurvey.co.uk/id/7000000000037256&gt; .

?a <http://www.w3.org/2004/02/skos/core#prefLabel&gt; ?name  .

}

If you are only interested in the bordering counties you can add an extra line to your query:

PREFIX spatialrelations: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/&gt;

select ?a ?name

where

{

?a spatialrelations:touches <http://data.ordnancesurvey.co.uk/id/7000000000037256&gt; .

?a <http://www.w3.org/2004/02/skos/core#prefLabel&gt; ?name  .

?a a <http://data.ordnancesurvey.co.uk/ontology/admingeo/County> .

}

Similarly, the following query returns all the county electoral divisions (and their names) within Hampshire:

PREFIX spatialrelations: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/&gt;

select ?a ?name

where

{

?a spatialrelations:within <http://data.ordnancesurvey.co.uk/id/7000000000017765&gt; .

?a <http://www.w3.org/2004/02/skos/core#prefLabel&gt; ?name  .

?a a <http://data.ordnancesurvey.co.uk/ontology/admingeo/CountyElectoralDivision> .

}

For convenience some shortcuts have been added to the data in this release. For certain nesting geographies, such as the county – district – parish or district – ward nestings, various new properties have been added. For example, the property ‘counyElectoralDivision‘ relates all counties to their constituent county electoral divisions. The above query can now be done in a simpler way:

PREFIX admingeo: <http://data.ordnancesurvey.co.uk/ontology/admingeo/&gt;

select ?a ?name

where

{

<http://data.ordnancesurvey.co.uk/id/7000000000017765&gt; admingeo:countyElectoralDivision ?a .

?a <http://www.w3.org/2004/02/skos/core#prefLabel&gt; ?name  .

}

Similar predicates such as ‘county‘, ‘district‘, ‘ward‘, ‘constituency‘ etc. provide similar shortcuts. For example, the following returns all the Westminster constituencies in South East England.

PREFIX admingeo: <http://data.ordnancesurvey.co.uk/ontology/admingeo/&gt;

select ?a ?name

where {

<http://data.ordnancesurvey.co.uk/id/7000000000041421&gt; admingeo:westminsterConstituency ?a .

?a <http://www.w3.org/2004/02/skos/core#prefLabel&gt; ?name  . }

The most significant introduction to this data is the inclusion of postcode information. The data now contains information about postcode units, postcode sectors, postcode districts and postcode areas. For each postcode unit an easting/northing coordinate value is given [2] along with the district, ward and county (where applicable) that contains said postcode unit. An example of this can be seen for the Ordnance Survey postcode SO16 4GU. Each postcode is also related to its containinb postcode area, sector and district.

The properties ‘ward‘, ‘district‘ and ‘county‘ relate a postcode to the relevant regions. The simple query:

PREFIX postcode: <http://data.ordnancesurvey.co.uk/ontology/postcode/&gt;

select ?district

where {

<http://data.ordnancesurvey.co.uk/id/postcodeunit/SO164GU&gt; postcode:district ?district .

}

returns the unitary authority that contains the postcode SO16 4GU.

This query:

PREFIX spatialrelations: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/&gt;

select ?postcode

where

{

?postcode spatialrelations:within <http://data.ordnancesurvey.co.uk/id/postcodearea/SO&gt; .

}

returns all the postcodes in the SO postcode area.

We can combine the above two queries to find the areas, along with their names, covered by the postcode area SO:

PREFIX spatialrelations: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/&gt;

PREFIX postcode: <http://data.ordnancesurvey.co.uk/ontology/postcode/&gt;

select distinct ?district ?name

where

{

?postcode spatialrelations:within <http://data.ordnancesurvey.co.uk/id/postcodearea/SO&gt; .

?postcode postcode:district ?district .

?district <http://www.w3.org/2004/02/skos/core#prefLabel&gt; ?name  .

}

Hopefully these few examples will give you enough information to fully explore this new release of the Ordnance Survey linked data. For those of you who don’t like SPARQL watch this space – hopefully we will soon(ish) have an API built on top of this data to allow for even easy access.

[1] you’ll notice the ‘isDefinedBy’ link currently returns a 404 – not for long I hope :)

[2] lat/long to follow

Follow

Get every new post delivered to your Inbox.

Join 2,189 other followers