<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Simon Hume &#187; opendata</title>
	<atom:link href="http://www.simonhume.com/tag/opendata/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.simonhume.com</link>
	<description>Geek, nerd &#38; all round good egg</description>
	<lastBuildDate>Tue, 10 Aug 2010 14:36:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Using SPARQL &amp; the data.gov.uk school data</title>
		<link>http://www.simonhume.com/2010/02/10/using-sparql-the-data-gov-uk-school-data/</link>
		<comments>http://www.simonhume.com/2010/02/10/using-sparql-the-data-gov-uk-school-data/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 12:48:24 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Local Government]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[opendata]]></category>

		<guid isPermaLink="false">http://www.simonhume.com/?p=3572</guid>
		<description><![CDATA[So i&#8217;ve been busy beavering away on the myDistrict project I&#8217;m developing for Stratford-on-Avon District Council, and part of this project is to retrieve various datasets from numerous API&#8217;s to enable the Stratford residents to get all their local information in one place. The basics are there, and we&#8217;ll be gathering the residents geo information [...]]]></description>
			<content:encoded><![CDATA[<p>So i&#8217;ve been busy beavering away on the myDistrict project I&#8217;m developing for Stratford-on-Avon District Council, and part of this project is to retrieve various datasets from numerous API&#8217;s to enable the Stratford residents to get all their local information in one place.</p>
<p>The basics are there, and we&#8217;ll be gathering the residents geo information when they register (or upgrade their existing website account) so we are able to query all these fantastic datasets from <a href="http://www.data.gov.uk" target="_blank">www.data.gov.uk</a> and more.</p>
<p>A bit stuck at first, I asked the Open Data guru from <a href="http://www.lichfielddc.gov.uk" target="_blank">Lichfield District Council</a>, <a href="http://www.pezholio.co.uk/" target="_blank">Stuart Harrison</a>, for some pointers. Stuart was very kind as to email through some sample code and links to blogs which reference the calls needed to access and unleash the data.</p>
<p>I thought I&#8217;d share some of this with you all, do with it what you will!</p>
<p><span id="more-3572"></span></p>
<p>A few sample snippets are below, but you&#8217;ll need to replace some parts (especially the local authority district reference eg 44UE) with your own data to get accurate results.</p>
<p><span style="text-decoration: line-through;">You can find your &#8216;id&#8217; number by having a look through the </span><a href="http://statistics.data.gov.uk/doc/county/44" target="_blank"><span style="text-decoration: line-through;">data.gov.uk lists here</span></a><span style="text-decoration: line-through;">. This is the Warwickshire County starting point, you&#8217;ll need to go up a level to country and search that way. It&#8217;s a bit fiddly! Once you&#8217;re in the right county, you&#8217;ll need to look for local authority district. If I find a better way, I&#8217;ll update this post!</span></p>
<p>UPDATE: Stuart Harrison has kindly <a href="http://www.pezholio.co.uk/snaclookup.php" target="_blank">written a nice service</a> to allow you to search for your council ID (or SNAC ID for the technical amongst you).</p>
<p>So, starting on the <a href="http://services.data.gov.uk/education/sparql" target="_blank">UK Government SPARQL form input page</a>, you can start to play with the various options to tailor your results accordingly.</p>
<p>To call back all the schools in your local authority (in this case, Stratford):</p>
<blockquote><p>prefix sch-ont:  &lt;http://education.data.gov.uk/def/school/&gt;</p>
<p>SELECT ?name  ?reference  WHERE {<br />
?school a sch-ont:School;<br />
sch-ont:establishmentName ?name;<br />
sch-ont:uniqueReferenceNumber ?reference ;<br />
sch-ont:districtAdministrative</p>
<p>&lt;http://statistics.data.gov.uk/id/local-authority-district/44UE&gt; .</p>
<p>}</p>
<p>ORDER BY ?name</p></blockquote>
<p>To filter by primary school you can add an extra couple of lines:</p>
<blockquote><p>prefix sch-ont:  &lt;http://education.data.gov.uk/def/school/&gt;</p>
<p>SELECT ?name  ?reference  WHERE {<br />
?school a sch-ont:School;<br />
sch-ont:establishmentName ?name;<br />
sch-ont:uniqueReferenceNumber ?reference ;<br />
sch-ont:districtAdministrative</p>
<p>&lt;http://statistics.data.gov.uk/id/local-authority-district/44UE&gt;  ;</p>
<p>sch-ont:uniqueReferenceNumber ?reference ; sch-ont:phaseOfEducation &lt;http://education.data.gov.uk/def/school/PhaseOfEducation_Primary&gt; .</p>
<p>}</p>
<p>ORDER BY ?name</p></blockquote>
<p>And to filter just secondary schools, you can make a small change also:</p>
<blockquote><p>prefix sch-ont:  &lt;http://education.data.gov.uk/def/school/&gt;</p>
<p>SELECT ?name  ?reference  WHERE {<br />
?school a sch-ont:School;<br />
sch-ont:establishmentName ?name;<br />
sch-ont:uniqueReferenceNumber ?reference ;<br />
sch-ont:districtAdministrative</p>
<p>&lt;http://statistics.data.gov.uk/id/local-authority-district/44UE&gt;  ;</p>
<p>sch-ont:uniqueReferenceNumber ?reference ; sch-ont:phaseOfEducation &lt;http://education.data.gov.uk/def/school/PhaseOfEducation_Secondary&gt; .</p>
<p>}</p>
<p>ORDER BY ?name</p></blockquote>
<p>You could also pull back which schools have nurseries attached, very handy!</p>
<blockquote><p>prefix sch-ont: &lt;http://education.data.gov.uk/def/school/&gt;<br />
prefix xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;</p>
<p>SELECT ?name WHERE {<br />
?school a sch-ont:School;<br />
sch-ont:establishmentName ?name;<br />
sch-ont:districtAdministrative &lt;http://statistics.data.gov.uk/id/local-authority-district/44UE&gt; ;</p>
<p>sch-ont:nurseryProvision &#8220;true&#8221;^^xsd:boolean ;</p>
<p>}</p>
<p>ORDER BY ?name</p></blockquote>
<p>Or you could pull back all the nursery schools available across the whole county. Just by tweaking a couple of search parameters:</p>
<blockquote><p>prefix sch-ont: &lt;http://education.data.gov.uk/def/school/&gt;<br />
prefix xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;</p>
<p>SELECT ?name WHERE {<br />
?school a sch-ont:School;<br />
sch-ont:establishmentName ?name;<br />
sch-ont:localAuthority &lt;http://statistics.data.gov.uk/id/local-education-authority/937&gt; ;</p>
<p>sch-ont:nurseryProvision &#8220;true&#8221;^^xsd:boolean ;</p>
<p>}</p>
<p>ORDER BY ?name</p></blockquote>
<p>And then, if you want to get really flash, you can return the 5 closest primary schools to your location. In this example, using easting &amp; northing data and adding address data to the mix as well:</p>
<blockquote><p>prefix sch-ont: &lt;http://education.data.gov.uk/def/school/&gt;<br />
prefix space: &lt;http://data.ordnancesurvey.co.uk/ontology/spatialrelations/&gt;</p>
<p>SELECT ?name ?address1 ?address2 ?town ?postcode ?easting ?northing ?reference ?WebsiteAddress ?SCUpreferredemail</p>
<p>WHERE { ?school a sch-ont:School ; sch-ont:districtAdministrative</p>
<p>&lt;http://statistics.data.gov.uk/id/local-authority-district/44UE&gt; ;<br />
sch-ont:establishmentName ?name;<br />
sch-ont:uniqueReferenceNumber ?reference ;<br />
space:easting ?easting ;<br />
space:northing ?northing ;</p>
<p>sch-ont:uniqueReferenceNumber ?reference ; sch-ont:phaseOfEducation</p>
<p>&lt;http://education.data.gov.uk/def/school/PhaseOfEducation_Primary&gt; .</p>
<p>OPTIONAL {</p>
<p>?school sch-ont:address ?address .<br />
?address sch-ont:address1 ?address1 ;<br />
sch-ont:address2 ?address2 ;<br />
sch-ont:town ?town ;<br />
sch-ont:postcode ?postcode .</p>
<p>}</p>
<p>OPTIONAL {<br />
?school sch-ont:WebsiteAddress ?WebsiteAddress ;</p>
<p>}</p>
<p>OPTIONAL {</p>
<p>?school sch-ont:SCUpreferredemail ?SCUpreferredemail ;</p>
<p>}</p>
<p>}</p>
<p>ORDER BY ASC(</p>
<p>((419997 &#8211; ?easting)* ( 419997 &#8211; ?easting))<br />
+ ((254702 &#8211; ?northing)* ( 254702 &#8211; ?northing))</p>
<p>)<br />
LIMIT 5<br />
OFFSET 0</p></blockquote>
<p>And this one, using longitude and latitude data:</p>
<blockquote>
<div id="_mcePaste">prefix geo: &lt;http://www.w3.org/2003/01/geo/wgs84_pos#&gt;</div>
<div id="_mcePaste">prefix sch-ont:  &lt;http://education.data.gov.uk/def/school/&gt;</div>
<div id="_mcePaste">SELECT ?name ?address1 ?address2 ?town ?postcode ?lat ?long ?reference ?WebsiteAddress ?SCUpreferredemail</div>
<div id="_mcePaste">WHERE {</div>
<div id="_mcePaste">?school a sch-ont:School;</div>
<div id="_mcePaste">sch-ont:establishmentName ?name;</div>
<div id="_mcePaste">sch-ont:districtAdministrative</div>
<div id="_mcePaste">&lt;http://statistics.data.gov.uk/id/local-authority-district/44UE&gt; ;</div>
<div id="_mcePaste">sch-ont:phaseOfEducation &lt;http://education.data.gov.uk/def/school/PhaseOfEducation_Primary&gt;;</div>
<div id="_mcePaste">sch-ont:uniqueReferenceNumber ?reference ;</div>
<div id="_mcePaste">geo:lat ?lat;</div>
<div id="_mcePaste">geo:long ?long.</div>
<div id="_mcePaste">OPTIONAL {</div>
<div id="_mcePaste">?school sch-ont:address ?address .</div>
<div id="_mcePaste">?address sch-ont:address1 ?address1 ;</div>
<div id="_mcePaste">sch-ont:address2 ?address2 ;</div>
<div id="_mcePaste">sch-ont:town ?town ;</div>
<div id="_mcePaste">sch-ont:postcode ?postcode .</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">OPTIONAL {</div>
<div id="_mcePaste">?school sch-ont:WebsiteAddress ?WebsiteAddress ;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">OPTIONAL {</div>
<div id="_mcePaste">?school sch-ont:SCUpreferredemail ?SCUpreferredemail ;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">ORDER BY ASC(</div>
<div id="_mcePaste">((52.190200973202 &#8211; ?lat)* ( 52.190200973202 &#8211; ?lat))</div>
<div id="_mcePaste">+ ((-1.7088976710252 &#8211; ?long)* ( -1.7088976710252 &#8211; ?long))</div>
<div id="_mcePaste">)</div>
<div id="_mcePaste">LIMIT 5</div>
<div id="_mcePaste">OFFSET 0</div>
</blockquote>
<p>This is really just touching the surface, I&#8217;ve got oodles of examples, far too many to post here.</p>
<p>If you have any questions, feel free to <a href="mailto:simon.hume@stratford-dc.gov.uk">email me</a> and I can help out where possible!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonhume.com/2010/02/10/using-sparql-the-data-gov-uk-school-data/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

