Reverse geocoding of minor stops to street names
--- a/busui/schedule_viewer.py
+++ b/busui/schedule_viewer.py
@@ -337,6 +337,14 @@
def handle_json_GET_stops(self, params):
schedule = self.server.schedule
return [StopToTuple(s) for s in schedule.GetStopList()]
+
+ def handle_json_GET_timingpoints(self, params):
+ schedule = self.server.schedule
+ matches = []
+ for s in schedule.GetStopList():
+ if s.stop_code.find("Wj") == -1:
+ matches.append(StopToTuple(s))
+ return matches
def handle_json_GET_stopsearch(self, params):
schedule = self.server.schedule
--- a/maxious-canberra-transit-feed/04-generateymlinclude.rb
+++ b/maxious-canberra-transit-feed/04-generateymlinclude.rb
@@ -44,8 +44,9 @@
# 0 = geoPo
# 1 = lat*100000
# 2 = lng*100000
+ # 3 = name
#pp time_point[0]
- f2.puts " - { name: #{stop[0]},stop_code: #{stop[0]}, lat: #{Float(stop[1])/10000000}, lng: #{Float(stop[2])/10000000}}"
+ f2.puts " - { name: #{stop[3]},stop_code: #{stop[0]}, lat: #{Float(stop[1])/10000000}, lng: #{Float(stop[2])/10000000}}"
end
f2.puts "routes:\n";
end
--- /dev/null
+++ b/maxious-canberra-transit-feed/04-locatebetweenpoints.reversegeocode.php
@@ -1,1 +1,38 @@
+<?php
+function getPage($url)
+{
+ $ch = curl_init($url);
+curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
+curl_setopt( $ch, CURLOPT_HEADER, 0 );
+$page = curl_exec($ch);
+curl_close($ch);
+return $page;
+}
+//
+// http://developers.cloudmade.com/wiki/geocoding-http-api/Documentation
+$conn = pg_connect("dbname=bus user=postgres password=snmc");
+if (!$conn) {
+ echo "An error occured.\n";
+ exit;
+}
+$sql = "Select * from stops where name is null";
+ $result_stops = pg_query($conn, $sql);
+ if (!$result_stops) {
+ cho("Error in SQL query: " . pg_last_error() ."<br>\n");
+ }
+ while ($stop = pg_fetch_assoc($result_stops)) {
+ echo "Processing ".$stop['geohash'] . " ... ";
+ $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));
+ $name = $contents->features[0]->properties->name;
+ echo "Saving $name ! <br>" ;
+ $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() ."<br>\n");
+ }
+ flush();
+ }
+?>
+
+