diff --git a/data/%%45^45E^45E480CD%%index.tpl.php b/data/%%45^45E^45E480CD%%index.tpl.php index d5481d1..3b96151 100644 --- a/data/%%45^45E^45E480CD%%index.tpl.php +++ b/data/%%45^45E^45E480CD%%index.tpl.php @@ -1,4 +1,4 @@ - _tpl_vars; $this->_smarty_include(array('smarty_include_tpl_file' => "header.tpl", 'smarty_include_vars' => array())); @@ -54,6 +54,7 @@ unset($_smarty_tpl_vars);
- You can help by writing a screen scraper for your local authority that was can import into plannignalerts.com. There are only 2 criteria for the screen scraper: + You can help by writing a screen scraper for your local authority that was can import into planningalerts.com. There are only 2 criteria for the screen scraper:
Other than that it's up to you. It can be in any language. You can host them yourself or we can host it for you.
- +You can grab the code for this site and view some developent tickets here and join our developer mailing list here. +
The most important thing you can do is publish your data in a simple format that is freely available on the internet. Something like this is good but we can work with most formats. Please get in touch if you would like to discuss how you can help. diff --git a/data/%%F7^F7F^F7F34188%%header.tpl.php b/data/%%F7^F7F^F7F34188%%header.tpl.php index 2e4f87e..20ff3ca 100644 --- a/data/%%F7^F7F^F7F34188%%header.tpl.php +++ b/data/%%F7^F7F^F7F34188%%header.tpl.php @@ -1,4 +1,4 @@ - diff --git a/docs/api.php b/docs/api.php index 95092e1..0205224 100644 --- a/docs/api.php +++ b/docs/api.php @@ -7,42 +7,124 @@ $api = new api; class api { //Properties - var $warnings = ""; - var $easting = 0; - var $northing = 0; - var $area_size = 0; + var $warnings = array(); var $applications; //Constructor function api() { if (isset($_GET['howto'])){ - $this->howto(); + redirect("apihowto.php");//this handles old links to this page + exit; } else { - $this->setup(); + if(isset($_GET['call'])){ + $this->setup(); + }else{ + $this->setup_old(); + } $this->bind(); } } - //setup - function setup (){ + //setup + function setup(){ + + //get the call type + $call = $_GET['call']; + switch ($call) { + case "postcode": + if(!isset($_GET['postcode']) || !is_postcode($_GET['area_size'])){ + array_push($this->warnings, "No valid postcode specified"); + } + if(!isset($_GET['area_size'])){ + array_push($this->warnings, "Area size specified"); + } + //all good, get the data + if(sizeof($this->warnings) == 0){ + $xy = postcode_to_location($_GET['postcode']); + $easting = $xy[0]; + $northing = $xy[1]; + $this->applications = Applications::query($easting, $northing, alert_size_to_meters($_GET['area_size'])); + } + + break; + case "point": + //validation + if(!isset($_GET['lat']) || !isset($_GET['lng'])){ + array_push($this->warnings, "No longitude or latitude was specified"); + } + if(!isset($_GET['area_size'])){ + array_push($this->warnings, "Area size specified"); + } + //all good, get the data + if(sizeof($this->warnings) == 0){ + $latlng = new LatLng($_GET['lat'], $_GET['lng']); + $xy = $latlng->toOSRef(); + $easting = $xy->easting; + $northing = $xy->northing; + $this->applications = Applications::query($easting, $northing, alert_size_to_meters($_GET['area_size'])); + } + break; + case "pointos": + //validation + if(!isset($_GET['easting']) || !isset($_GET['northing'])){ + array_push($this->warnings, "No easting or northing was specified"); + } + if(!isset($_GET['area_size'])){ + array_push($this->warnings, "Area size specified"); + } + //all good, get the data + if(sizeof($this->warnings) == 0){ + $this->applications = Applications::query($_GET['easting'], $_GET['$northing'], alert_size_to_meters($_GET['area_size'])); + } + break; + case "authority": + //validation + if(!isset($_GET['authority'])){ + array_push($this->warnings, "No authority name specified"); + } + + //all good, get the data + if(sizeof($this->warnings) == 0){ + $this->applications = Applications::query_authority($_GET['authority']); + } + break; + case "area": + //validation + if(!isset($_GET['bottom_left_lat']) || !isset($_GET['bottom_left_lng']) || !isset($_GET['top_right_lat']) || !isset($_GET['top_right_lng'])){ + array_push($this->warnings, "Bounding box was not specified"); + } + + //all good, get the data + if(sizeof($this->warnings) == 0){ + $bottom_left_latlng = new LatLng($_GET['bottom_left_lat'], $_GET['bottom_left_lng']); + $bottom_left_xy = $latlng->toOSRef(); + $top_right_latlng = new LatLng($_GET['bottom_left_lat'], $_GET['bottom_left_lng']); + $top_right_xy = $latlng->toOSRef(); + + $this->applications = Applications::query_area($bottom_left_xy->easting, $bottom_left_xy->northing, $top_right_xy->easting, $top_right_xy->northing); + } + break; + default: + $this->warnings = "No call type specified"; + } + + } + + + //setup old (maintains the original mini api) + function setup_old (){ //Grab the postcode and area size from the get string - if (!isset($_GET['area_size'])){ //check is_numeric and isn't too big - $this->warnings .= "No area size specified "; + array_push($this->warnings, "No area size specified"); } - if (!(isset($_GET['lat']) && isset($_GET['lng'])) - || !(isset($_GET['postcode'])) ) { - $this->warmings .= "No location specified "; - } - - if ($this->warnings == ""){ - + + if (sizeof($this->warnings) == 0){ //Get OS ref from postcode if (isset($_GET['postcode'])) { $xy = postcode_to_location($_GET['postcode']); $this->easting = $xy[0]; - $this->northing = $xy[1]; + $this->northing = $xy[1]; } else { $latlng = new LatLng($_GET['lat'], $_GET['lng']); $xy = $latlng->toOSRef(); diff --git a/docs/css/main.css b/docs/css/main.css index 239e7ab..597de94 100644 --- a/docs/css/main.css +++ b/docs/css/main.css @@ -1,4 +1,4 @@ -body {font-family:georgia, serif; text-align:center;line-height:2em;margin:0; +body {font-family:georgia, serif; text-align:center;line-height:1.8em;margin:0; color:#0f0f0f;} #divPage {width:500px; margin:0 auto;background:white;text-align:left;} h1 {font-weight:normal; font-size:2.7em;padding-left:115px;padding-bottom:0.2em;padding-top:0.1em;} @@ -58,6 +58,14 @@ div.attention h3 {font-size:2em;padding-bottom:0.3em;font-style:normal; color:#4 dl.faq dt {color:#96ca2f;font-style:italic;} dl.faq dd {padding-left:0;margin-left:0;} +/* api */ +div.apiitem {border:dotted 1px #808080;background:#fafafa;padding:10px;margin-bottom:1em;} +div.apiitem code {background:white;display:block;padding:10px;border:solid 1px #808080; +word-wrap: break-word} +div.apiitem code em {color:#808080;} +div.apiitem p {font-size:0.8em;margin:0;padding:0;line-height:1.5em;margin-bottom:1em;} +p.apiexamples {position:relative; top:0.7em;} + /* infobox */ .infobox {background:#fdd9ea; font-size:0.9em;} @@ -75,6 +83,8 @@ a {color:#22579C;} /* Footer */ #divFooter {font-size:0.9em; padding-top:1.5em;position:relative;} +#divFooter #aOpen {display:block;width:80px;height:15px;background:red url(../images/opendata.png); + position:absolute; right:140px; top:40px;} #divFooter #aHosted {display:block;width:130px;height:35px;background:url(../images/hosted.png); position:absolute; right:0; top:30px;} #divFooter ul {border-top:dotted 1px #808080;padding-top:3px;padding-bottom:20px;} diff --git a/docs/include/application.php b/docs/include/application.php index 7c2d268..27e3317 100644 --- a/docs/include/application.php +++ b/docs/include/application.php @@ -3,145 +3,175 @@ require_once('config.php'); require_once('DB.php'); - class Application{ - var $authority_id = 0; - var $council_reference = ""; - var $date_recieved = ""; - var $date_scraped =""; - var $address = ""; - var $postcode = ""; - var $description = ""; - var $status = ""; - var $info_url = ""; - var $info_tinyurl = ""; - var $comment_url = ""; - var $comment_tinyurl = ""; - var $map_url = ""; - var $x = 0; - var $y = 0; +class Application{ + var $authority_id = 0; + var $council_reference = ""; + var $date_recieved = ""; + var $date_scraped =""; + var $address = ""; + var $postcode = ""; + var $description = ""; + var $status = ""; + var $info_url = ""; + var $info_tinyurl = ""; + var $comment_url = ""; + var $comment_tinyurl = ""; + var $map_url = ""; + var $x = 0; + var $y = 0; - #lat/lon used by rss.tpl, not yet in schema - var $lat = 0; - var $lon = 0; - - #authority name in join'd table 'authority' - var $authority_name = ""; - - function exists(){ - - $db = DB::connect(DB_CONNECTION_STRING); - - $exists = false; - $council_reference = $db->quote($this->council_reference); - $authority_id = $db->quote($this->authority_id); - - $sql = "select application_id - from application - where council_reference = $council_reference - and authority_id = $authority_id"; + #lat/lon used by rss.tpl, not yet in schema + var $lat = 0; + var $lon = 0; - if(sizeof($db->getAll($sql)) >0){ - $exists = true; - } - return $exists; - } - - //Save - function save(){ - - $db = DB::connect(DB_CONNECTION_STRING); - - $council_reference = $db->quote($this->council_reference); - $address = $db->quote($this->address); - $postcode = $db->quote($this->postcode); - $description = $db->quote($this->description); - $info_url = $db->quote($this->info_url); - $info_tinyurl = $db->quote($this->info_tinyurl); - $comment_url = $db->quote($this->comment_url); - $comment_tinyurl = $db->quote($this->comment_tinyurl); - $authority_id = $db->quote($this->authority_id); - $x = $db->quote($this->x); - $y = $db->quote($this->y); - $date_scraped = $db->quote($this->date_scraped); - $map_url = $db->quote($this->map_url); - - $sql ="insert into application - ( - council_reference, - address, - postcode, - description, - info_url, - info_tinyurl, - comment_url, - comment_tinyurl, - authority_id, - x, - y, - date_scraped, - map_url - ) - values( - $council_reference, - $address, - $postcode, - $description, - $info_url, - $info_tinyurl, - $comment_url, - $comment_tinyurl, - $authority_id, - $x, - $y, - $date_scraped, - $map_url - )"; - - $db->query($sql); + #authority name in join'd table 'authority' + var $authority_name = ""; + + function exists(){ + + $db = DB::connect(DB_CONNECTION_STRING); + + $exists = false; + $council_reference = $db->quote($this->council_reference); + $authority_id = $db->quote($this->authority_id); + + $sql = "select application_id + from application + where council_reference = $council_reference + and authority_id = $authority_id"; + if(sizeof($db->getAll($sql)) >0){ + $exists = true; } + return $exists; + } + + //Save + function save(){ + + $db = DB::connect(DB_CONNECTION_STRING); + + $council_reference = $db->quote($this->council_reference); + $address = $db->quote($this->address); + $postcode = $db->quote($this->postcode); + $description = $db->quote($this->description); + $info_url = $db->quote($this->info_url); + $info_tinyurl = $db->quote($this->info_tinyurl); + $comment_url = $db->quote($this->comment_url); + $comment_tinyurl = $db->quote($this->comment_tinyurl); + $authority_id = $db->quote($this->authority_id); + $x = $db->quote($this->x); + $y = $db->quote($this->y); + $date_scraped = $db->quote($this->date_scraped); + $map_url = $db->quote($this->map_url); + + $sql ="insert into application + ( + council_reference, + address, + postcode, + description, + info_url, + info_tinyurl, + comment_url, + comment_tinyurl, + authority_id, + x, + y, + date_scraped, + map_url + ) + values( + $council_reference, + $address, + $postcode, + $description, + $info_url, + $info_tinyurl, + $comment_url, + $comment_tinyurl, + $authority_id, + $x, + $y, + $date_scraped, + $map_url + )"; + + $db->query($sql); } - - class Applications{ - function query($x,$y,$d) { - $db = DB::connect(DB_CONNECTION_STRING); - $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, full_name - from application - inner join authority on application.authority_id = authority.authority_id - where application.x > " . $db->quote($x - $d) . " and application.x < " . $db->quote($x + $d) . - " and application.y > " . $db->quote($y - $d) . " and application.y < " . $db->quote($y + $d) . - " order by date_scraped desc limit 100"; +} - $application_results = $db->getAll($sql); +class Applications{ - $applications = array(); - if (sizeof($application_results) > 0) { - for ($i=0; $i < sizeof($application_results); $i++) { - $application = new application(); - $application->council_reference = $application_results[$i][0]; - $application->address = $application_results[$i][1]; - $application->postcode = $application_results[$i][2]; - $application->description = $application_results[$i][3]; - $application->info_url = $application_results[$i][4]; - $application->comment_url = $application_results[$i][5]; - $application->map_url = $application_results[$i][6]; - $application->x = $application_results[$i][7]; - $application->y = $application_results[$i][8]; - $application->date_received = $application_results[$i][9]; - $application->authority_name = $application_results[$i][10]; + //by point + function query($x,$y,$d) { + $db = DB::connect(DB_CONNECTION_STRING); + $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, full_name + from application + inner join authority on application.authority_id = authority.authority_id + where application.x > " . $db->quote($x - $d) . " and application.x < " . $db->quote($x + $d) . + " and application.y > " . $db->quote($y - $d) . " and application.y < " . $db->quote($y + $d) . + " order by date_scraped desc limit 100"; - $os = new OSRef($application->x, $application->y); - $latlng = $os->toLatLng(); - $application->lat = $latlng->lat; - $application->lon = $latlng->lng; - array_push($applications, $application); - } - } + $application_results = $db->getAll($sql); + return applications::load_applications($application_results); + } + + //by area + function query_area($x1,$y1,$x2,$y2) { + $db = DB::connect(DB_CONNECTION_STRING); + $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, full_name + from application + inner join authority on application.authority_id = authority.authority_id + where application.x > " . $db->quote($x1) . " and application.x < " . $db->quote($x2) . + " and application.y > " . $db->quote($y1) . " and application.y < " . $db->quote($y2) . + " order by date_scraped desc limit 100"; + + $application_results = $db->getAll($sql); + return applications::load_applications($application_results); + } + + //by authority + function query_authority($authority_short_name) { + $db = DB::connect(DB_CONNECTION_STRING); + $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, full_name + from application + inner join authority on application.authority_id = authority.authority_id + where authority.short_name = " . $db->quote($authority_short_name) ." order by date_scraped desc limit 100"; - return $applications; + $application_results = $db->getAll($sql); + return applications::load_applications($application_results); + } + + function load_applications($application_results){ + $applications = array(); + if (sizeof($application_results) > 0) { + for ($i=0; $i < sizeof($application_results); $i++) { + $application = new application(); + $application->council_reference = $application_results[$i][0]; + $application->address = $application_results[$i][1]; + $application->postcode = $application_results[$i][2]; + $application->description = $application_results[$i][3]; + $application->info_url = $application_results[$i][4]; + $application->comment_url = $application_results[$i][5]; + $application->map_url = $application_results[$i][6]; + $application->x = $application_results[$i][7]; + $application->y = $application_results[$i][8]; + $application->date_received = $application_results[$i][9]; + $application->authority_name = $application_results[$i][10]; + + $os = new OSRef($application->x, $application->y); + $latlng = $os->toLatLng(); + $application->lat = $latlng->lat; + $application->lon = $latlng->lng; + array_push($applications, $application); + } } + + return $applications; } +} ?> diff --git a/docs/include/scraper_support.php b/docs/include/scraper_support.php index a2d20aa..d1315cf 100644 --- a/docs/include/scraper_support.php +++ b/docs/include/scraper_support.php @@ -419,4 +419,8 @@ function throw_error($message){ throw new exception($message); } +function redirect ($url){ + header("Location: $url"); +} + ?> diff --git a/docs/templates/apihowto.tpl b/docs/templates/apihowto.tpl index 58a8162..f4f2924 100644 --- a/docs/templates/apihowto.tpl +++ b/docs/templates/apihowto.tpl @@ -1,25 +1,109 @@ {include file="header.tpl"}
- Planning application data is available programmatically as GeoRSS feeds. GeoRSS can be used in almost most all web mapping APIs and desktop GIS software, and in services like mapufacture and Yahoo Pipes. -
++ Planning application data is available programmatically as GeoRSS feeds. GeoRSS can be used in almost most all web mapping APIs and desktop GIS software, and in services like mapufacture and Yahoo Pipes. +
++ Just want the raw data? You can also download it here. (gzipped mysql database dump with all user information removed). +
-
- Construct an api request as follows.
- Either lat/lng or postcode is required. area_size is always required.
-
+ Return applications near a given postcode. The area included is a square either 400m (s), 800m (m) or 4000m (l) with the postcode at it's center. +
+
+ http://www.planningalerts.com/api.php?call=postcode
&postcode=[some postcode]&area_size=['s' 'm' or 'l']
+
+ + view example + view on a map +
+
- http://www.planningalerts.com/api.php?
- lat=[some latitude]
- &lng=[some longitude]
- &postcode=[some postcode]
- &area_size=['s' 'm' or 'l']
-
-
- - an example query -
+ ++ Return applications near a given longitude/latitude. The area included is a square either 400m (s), 800m (m) or 4000m (l) with the longitude/latitude at it's center. +
+
+ http://www.planningalerts.com/api.php?call=point
&lat=[some latitude]&lng=[some longitude]area_size=['s' 'm' or 'l']
+
+ + view example + view on a map +
++ Return applications near a given longitude/latitude. The area included is a square either 400m (s), 800m (m) or 4000m (l) with the OSGB point at it's center. +
+
+ http://www.planningalerts.com/api.php?call=pointos
&easting=[some easting]&northing=[some northing]area_size=['s' 'm' or 'l']
+
+ + view example + view on a map +
++ Return applications within a rectangle defined by longitude/latitude. +
+
+ http://www.planningalerts.com/api.php?call=area
&bottom_left_lat=[some latitude]&bottom_left_lng=[some longitude]&top_right_lat=[some latitude]&top_right_lng=[some longitude]
+
+ + view example + view on a map +
++ Return applications within a rectangle defined by OSGB coordinates. +
+
+ http://www.planningalerts.com/api.php?call=areaos
&bottom_left_easting=[some easting]&bottom_left_northing=[some northing]&top_right_easting=[some easting]&top_right_northing=[some northing]
+
+ + view example + view on a map +
++ Return applications for a specific planning authority (e.g. a local council) by authority short name. +
+
+ http://www.planningalerts.com/api.php?call=authority
&authority_short_name=[some name]
+
+ + view example + view on a map +
++ Both the raw data and data via the api are licensed under the Creative Commons Attribution-ShareAlike 2.0 license. The license granted in relation to the 'Work' should be read broadly to relate not only copyright but all other IP rights present in this dataset including, for example, any Database rights. +
{include file="footer.tpl"} diff --git a/docs/templates/faq.tpl b/docs/templates/faq.tpl index b578c4e..88eb5fc 100644 --- a/docs/templates/faq.tpl +++ b/docs/templates/faq.tpl @@ -22,8 +22,12 @@ Yes please! To be able to cover the whole country we need help in writing screen scrapers to search the websites of every local authority in the country. If you'd like to write one for your local council get in touch.