From: root Date: Tue, 27 Apr 2010 14:18:53 +0000 Subject: Convert to GeoRSS for nice popups X-Git-Url: https://maxious.lambdacomplex.org/git/?p=bus.git&a=commitdiff&h=9fc21293feea4a168499442e5c501cc9a0ed4e40 --- Convert to GeoRSS for nice popups --- --- a/display.php +++ b/display.php @@ -1,23 +1,8 @@ - --- /dev/null +++ b/displaystops.georss.php @@ -1,1 +1,43 @@ + +Bus Stops from OSM'; +$conn = pg_connect("dbname=openstreetmap user=postgres password=snmc"); +if (!$conn) { + echo "An error occured.\n"; + exit; +} +/*SELECT * from current_node_tags, (Select id FROM current_node_tags WHERE "v" LIKE '%bus%') as a +where a.id = current_node_tags.id; */ +$result_stops = pg_query($conn, "Select * FROM current_node_tags INNER JOIN current_nodes ON +current_node_tags.id=current_nodes.id WHERE v LIKE '%bus%' "); +if (!$result_stops) { + echo "An stops retirieve error occured.\n"; + exit; +} + +while ($stop = pg_fetch_assoc($result_stops)) { + echo "\n\n"; + echo ""; +$result_stopkeys = pg_query($conn, "SELECT * from current_node_tags where id = {$stop['id']};"); +if (!$result_stopkeys) { + echo "An stops keys retirieve error occured.\n"; + exit; +} +$name = ""; +while ($stopkeys = pg_fetch_assoc($result_stopkeys)) { +echo htmlspecialchars(print_r($stopkeys,true)); +$name .= htmlspecialchars($stopkeys['v']); +} +echo ""; + echo "$name"; + +echo " ";echo ($stop['latitude']/10000000)." ".($stop['longitude']/10000000); +echo " "; +echo ''; +} + +echo "\n\n"; +?> --- a/displaystops.kml.php +++ /dev/null @@ -1,58 +1,1 @@ - -'; -echo ''; -echo ''; -$conn = pg_connect("dbname=openstreetmap user=postgres password=snmc"); -if (!$conn) { - echo "An error occured.\n"; - exit; -} -/*SELECT * from current_node_tags, (Select id FROM current_node_tags WHERE "v" LIKE '%bus%') as a -where a.id = current_node_tags.id; */ -$result_stops = pg_query($conn, "Select * FROM current_node_tags INNER JOIN current_nodes ON -current_node_tags.id=current_nodes.id WHERE v LIKE '%bus%' "); -if (!$result_stops) { - echo "An stops retirieve error occured.\n"; - exit; -} - -while ($stop = pg_fetch_assoc($result_stops)) { - echo "\n\n"; - echo ""; -$result_stopkeys = pg_query($conn, "SELECT * from current_node_tags where id = {$stop['id']};"); -if (!$result_stopkeys) { - echo "An stops keys retirieve error occured.\n"; - exit; -} -$name = ""; -while ($stopkeys = pg_fetch_assoc($result_stopkeys)) { -echo htmlspecialchars(print_r($stopkeys,true)); -$name .= htmlspecialchars($stopkeys['v']); -} -echo ""; - echo "$name"; - -echo "#target"; -echo "\n "; - echo ($stop['longitude']/10000000).",".($stop['latitude']/10000000)."\n"; -echo " "; -echo ''; -} - -echo "\n\n"; -?> --- /dev/null +++ b/displaytimepoints.georss.php @@ -1,1 +1,26 @@ + '; +echo ' Points'; +$conn = pg_connect("dbname=bus user=postgres password=snmc"); +if (!$conn) { + echo "An error occured.\n"; + exit; +} +$result_timepoints = pg_query($conn, "Select * FROM timing_point where lat is not null and lng is not null "); +if (!$result_timepoints) { + echo "An timepoints retirieve error occured.\n"; + exit; +} + +while ($timepoint = pg_fetch_assoc($result_timepoints)) { + echo ""; + echo "".htmlspecialchars ($timepoint['name']).""; + echo "".htmlspecialchars($timepoint['name']).""; +echo " ".($timepoint['lat']/10000000)." ".($timepoint['lng']/10000000).""; +echo "\n"; +} + +echo "\n\n"; +?> --- a/displaytimepoints.kml.php +++ /dev/null @@ -1,58 +1,1 @@ - -'; -echo ''; -echo ''; -$conn = pg_connect("dbname=openstreetmap user=postgres password=snmc"); -if (!$conn) { - echo "An error occured.\n"; - exit; -} -/*SELECT * from current_node_tags, (Select id FROM current_node_tags WHERE "v" LIKE '%bus%') as a -where a.id = current_node_tags.id; */ -$result_stops = pg_query($conn, "Select * FROM current_node_tags INNER JOIN current_nodes ON -current_node_tags.id=current_nodes.id WHERE v LIKE '%bus%' "); -if (!$result_stops) { - echo "An stops retirieve error occured.\n"; - exit; -} - -while ($stop = pg_fetch_assoc($result_stops)) { - echo "\n\n"; - echo ""; -$result_stopkeys = pg_query($conn, "SELECT * from current_node_tags where id = {$stop['id']};"); -if (!$result_stopkeys) { - echo "An stops keys retirieve error occured.\n"; - exit; -} -$name = ""; -while ($stopkeys = pg_fetch_assoc($result_stopkeys)) { -echo htmlspecialchars(print_r($stopkeys,true)); -$name .= htmlspecialchars($stopkeys['v']); -} -echo ""; - echo "$name"; - -echo "#target"; -echo "\n "; - echo ($stop['longitude']/10000000).",".($stop['latitude']/10000000)."\n"; -echo " "; -echo ''; -} - -echo "\n\n"; -?> --- a/maxious-canberra-transit-feed/03-locatetimepoints.rb +++ b/maxious-canberra-transit-feed/03-locatetimepoints.rb @@ -3,6 +3,26 @@ require 'highline.rb' include HighLine + +require 'rubygems' +require 'json' +require 'net/http' +def cbr_geocode(query) + base_url = "http://geocoding.cloudmade.com/daa03470bb8740298d4b10e3f03d63e6/geocoding/v2/find.js?query=" + url = "#{base_url}#{URI.encode(query)}&bbox=-35.47,148.83,-35.16,149.25&return_location=true" + resp = Net::HTTP.get_response(URI.parse(url)) + data = resp.body + + # we convert the returned JSON data to native Ruby + # data structure - a hash + result = JSON.parse(data) + + # if the hash has 'Error' as a key, we raise an error + if result.has_key? 'Error' + raise "web service error" + end + return result +end require 'yaml' require 'pp' @@ -31,7 +51,7 @@ if ask_if("Insert Timing Point names to database?") $time_points.each do |time_point| begin - time_point = time_point.gsub(/\\/, '\&\&').gsub(/'/, "''") + time_point = time_point.gsub(/\\/, '\&\&').gsub(/'/, "''").gsub("St", "%") res = connbus.exec("INSERT INTO timing_point (name) VALUES ('#{time_point}')") puts "Put '#{time_point}' into DB" rescue PGError => e @@ -111,6 +131,31 @@ null_points.each do |null_point_name| pp null_point_name + name = null_point_name.to_s.gsub(/\\/, '\&\&').gsub(/'/, "''") + results = cbr_geocode(null_point_name[0]) + if !results.empty? + results['features'].each_with_index { |feature,index| + print "#{index}: #{feature['properties']['name']} (#{feature['location']}) => #{feature['centroid']['coordinates']}\n" + } + nodeID = ask("Enter selected node ID:", :integer) + if results['features'].at(nodeID) != nil + node = results['features'][nodeID] + puts "Location #{node['centroid']['coordinates'][0]},#{node['centroid']['coordinates'][1]} for #{null_point_name}" + begin + res = connbus.exec("UPDATE timing_point SET lat = #{node['centroid']['coordinates'][0]*10000000}, lng = + #{node['centroid']['coordinates'][1]*10000000},guess = true WHERE name = '#{name}'") + puts "Put '#{null_point_name}' into DB" + rescue PGError => e + puts "Error inserting '#{null_point_name}' to DB #{e}" + ask_if("Continue?") + #conn.close() if conn + end + else + puts "Uhh, there was no suggestion ID like that. Try again next time!" + end + else + puts "Uhh, there were no geocoding results. Try again next time!" + end end end