forked from easyrdf/easyrdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uk_postcode.php
73 lines (66 loc) · 2.86 KB
/
uk_postcode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Resolving UK postcodes using uk-postcodes.com
*
* Another basic example that demonstrates registering namespaces,
* loading RDF data from the web and then directly displaying
* literals from the graph on the page.
*
* @package EasyRdf
* @copyright Copyright (c) Nicholas J Humfrey
* @license http://unlicense.org/
*/
require_once realpath(__DIR__.'/..')."/vendor/autoload.php";
require_once __DIR__."/html_tag_helpers.php";
\EasyRdf\RdfNamespace::set('postcode', 'http://data.ordnancesurvey.co.uk/ontology/postcode/');
\EasyRdf\RdfNamespace::set('sr', 'http://data.ordnancesurvey.co.uk/ontology/spatialrelations/');
\EasyRdf\RdfNamespace::set('eg', 'http://statistics.data.gov.uk/def/electoral-geography/');
\EasyRdf\RdfNamespace::set('ag', 'http://statistics.data.gov.uk/def/administrative-geography/');
\EasyRdf\RdfNamespace::set('osag', 'http://data.ordnancesurvey.co.uk/ontology/admingeo/');
?>
<html>
<head>
<title>EasyRdf UK Postcode Resolver</title>
<style type="text/css" media="all">
#map
{
border: 1px gray solid;
float: right;
margin: 0 0 20px 20px;
}
th { text-align: right }
td { padding: 5px; }
</style>
</head>
<body>
<h1>EasyRdf UK Postcode Resolver</h1>
<?= form_tag() ?>
<?= text_field_tag('postcode', 'W1A 1AA', array('size'=>10)) ?>
<?= submit_tag() ?>
<?= form_end_tag() ?>
<?php
if (isset($_REQUEST['postcode'])) {
$postcode = str_replace(' ', '', strtoupper($_REQUEST['postcode']));
$docuri = "http://data.ordnancesurvey.co.uk/doc/postcodeunit/$postcode";
$graph = \EasyRdf\Graph::newAndLoad($docuri);
// Get the first resource of type PostcodeUnit
$res = $graph->get('postcode:PostcodeUnit', '^rdf:type');
if ($res) {
$lat = $res->get('geo:lat');
$long = $res->get('geo:long');
print "<iframe width='500' height='350' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='https://www.openlinkmap.org/small.php?lat=$lat&lon=$long&zoom=14' style='border: 1px solid black'></iframe>";
print "<table id='facts'>\n";
print "<tr><th>Longitude:</th><td>" . $res->get('geo:long') . "</td></tr>\n";
print "<tr><th>Latitude:</th><td>" . $res->get('geo:lat') . "</td></tr>\n";
print "<tr><th>Easting:</th><td>" . $res->get('sr:easting') . "</td></tr>\n";
print "<tr><th>Northing:</th><td>" . $res->get('sr:northing') . "</td></tr>\n";
print "<tr><th>District:</th><td>" . $res->get('postcode:district')->label() . "</td></tr>\n";
print "<tr><th>Ward:</th><td>" . $res->get('postcode:ward')->label() . "</td></tr>\n";
print "</table>\n";
print "<div style='clear: both'></div>\n";
}
print $graph->dump();
}
?>
</body>
</html>