--- a/maxious-canberra-transit-feed/04-locatebetweenpoints.reversegeocode.php
+++ b/maxious-canberra-transit-feed/04-locatebetweenpoints.reversegeocode.php
@@ -15,24 +15,68 @@
echo "An error occured.\n";
exit;
}
+echo "reverse geocode stops
";
$sql = "Select * from stops where name is null or suburb is null";
$result_stops = pg_query($conn, $sql);
if (!$result_stops) {
echo("Error in SQL query: " . pg_last_error() ."
\n");
}
while ($stop = pg_fetch_assoc($result_stops)) {
- echo "Processing ".$stop['geohash'] . " ... ";
+ if ($stop['name'] == "") {
+ echo "Processing ".$stop['geohash'] . " streetname ... ";
$url = "http://geocoding.cloudmade.com/daa03470bb8740298d4b10e3f03d63e6/geocoding/v2/find.js?around=".($stop['lat']/10000000).",".($stop['lng']/10000000)."&distance=closest&object_type=road";
$contents = json_decode(getPage($url));
- print_r($contents);
+ //print_r($contents);
$name = $contents->features[0]->properties->name;
- //todo suburb/locality select * from suburbs where the_geom @> 'POINT(149.075704592122 -35.21751569325)'::geometry
echo "Saving $name !
" ;
$result_save = pg_query($conn, "UPDATE stops set name = '".pg_escape_string($name)."' where geohash = '{$stop['geohash']}' ");
if (!$result_save) {
echo("Error in SQL query: " . pg_last_error() ."
\n");
+ }
+ }
+ if ($stop['suburb'] == "") {
+ echo "Processing ".$stop['geohash'] . " suburb ... ";
+ $sql = "select * from suburbs where the_geom @> 'POINT(".($stop['lng']/10000000)." ".($stop['lat']/10000000).")'::geometry";
+ $result_suburbs = pg_query($conn, $sql);
+ if (!$result_suburbs) {
+ echo("Error in SQL query: " . pg_last_error() ."
\n");
}
- die();
+ $suburbs = "";
+ while ($suburb = pg_fetch_assoc($result_suburbs)) {
+ $suburbs .= $suburb['name_2006'].";";
+ }
+ echo "Saving $suburbs !
" ;
+ $result_save = pg_query($conn, "UPDATE stops set suburb = '".pg_escape_string($suburbs)."' where geohash = '{$stop['geohash']}' ");
+ if (!$result_save) {
+ echo("Error in SQL query: " . pg_last_error() ."
\n");
+ }
+ }
+ flush();
+ }
+echo "reverse geocode timing points
";
+$sql = "Select * from timing_point where suburb is null";
+ $result_timingpoints = pg_query($conn, $sql);
+ if (!$result_timingpoints) {
+ echo("Error in SQL query: " . pg_last_error() ."
\n");
+ }
+ while ($timingpoint = pg_fetch_assoc($result_timingpoints)) {
+ if ($timingpoint['suburb'] == "") {
+ echo "Processing ".$timingpoint['name'] . " suburb ... ";
+ $sql = "select * from suburbs where the_geom @> 'POINT(".($timingpoint['lng']/10000000)." ".($timingpoint['lat']/10000000).")'::geometry";
+ $result_suburbs = pg_query($conn, $sql);
+ if (!$result_suburbs) {
+ echo("Error in SQL query: " . pg_last_error() ."
\n");
+ }
+ $suburbs = "";
+ while ($suburb = pg_fetch_assoc($result_suburbs)) {
+ $suburbs .= $suburb['name_2006'].";";
+ }
+ echo "Saving $suburbs !
" ;
+ $result_save = pg_query($conn, "UPDATE timing_point set suburb = '".pg_escape_string($suburbs)."' where name = '".pg_escape_string($timingpoint['name'])."'");
+ if (!$result_save) {
+ echo("Error in SQL query: " . pg_last_error() ."
\n");
+ }
+ }
flush();
}