def main(): usage = """usage: python gdb_link_gtfs_gtfs.py <graphdb_filename> <gtfsdb_filename> <range>""" parser = OptionParser(usage=usage) (options, args) = parser.parse_args() if len(args) != 3: parser.print_help() exit(-1) graphdb_filename = args[0] gtfsdb_filename = args[1] range = float(args[2]) gtfsdb = GTFSDatabase( gtfsdb_filename ) gdb = GraphDatabase( graphdb_filename ) n_stops = gtfsdb.count_stops() for i, (stop_id, stop_name, stop_lat, stop_lon) in enumerate( gtfsdb.stops() ): print "%d/%d %s"%(i,n_stops,stop_id), station_vertex_id = "sta-%s"%stop_id for link_stop_id, link_stop_name, link_stop_lat, link_stop_lon in gtfsdb.nearby_stops( stop_lat, stop_lon, range ): if link_stop_id == stop_id: continue print ".", link_length = vincenty( stop_lat, stop_lon, link_stop_lat, link_stop_lon) link_station_vertex_id = "sta-%s"%link_stop_id gdb.add_edge( station_vertex_id, link_station_vertex_id, Street("link", link_length) ) print ""
def main(): usage = """usage: python gdb_link_osm_gtfs.py <graphdb_filename> <osmdb_filename> <gtfsdb_filename>""" parser = OptionParser(usage=usage) (options, args) = parser.parse_args() if len(args) != 3: parser.print_help() exit(-1) graphdb_filename = args[0] osmdb_filename = args[1] gtfsdb_filename = args[2] gtfsdb = GTFSDatabase( gtfsdb_filename ) osmdb = OSMDB( osmdb_filename ) gdb = GraphDatabase( graphdb_filename ) n_stops = gtfsdb.count_stops() for i, (stop_id, stop_name, stop_lat, stop_lon) in enumerate( gtfsdb.stops() ): print "%d/%d"%(i,n_stops) nd_id, nd_lat, nd_lon, nd_dist = osmdb.nearest_node( stop_lat, stop_lon ) station_vertex_id = "sta-%s"%stop_id osm_vertex_id = "osm-%s"%nd_id print station_vertex_id, osm_vertex_id gdb.add_edge( station_vertex_id, osm_vertex_id, Link() ) gdb.add_edge( osm_vertex_id, station_vertex_id, Link() )
def main(): usage = """usage: python gdb_link_gtfs_gtfs.py <graphdb_filename> <gtfsdb_filename> <range>""" parser = OptionParser(usage=usage) (options, args) = parser.parse_args() if len(args) != 3: parser.print_help() exit(-1) graphdb_filename = args[0] gtfsdb_filename = args[1] range = float(args[2]) gtfsdb = GTFSDatabase(gtfsdb_filename) gdb = GraphDatabase(graphdb_filename) n_stops = gtfsdb.count_stops() for i, (stop_id, stop_name, stop_lat, stop_lon) in enumerate(gtfsdb.stops()): print "%d/%d %s" % (i, n_stops, stop_id), station_vertex_id = "sta-%s" % stop_id for link_stop_id, link_stop_name, link_stop_lat, link_stop_lon in gtfsdb.nearby_stops( stop_lat, stop_lon, range): if link_stop_id == stop_id: continue print ".", link_length = vincenty(stop_lat, stop_lon, link_stop_lat, link_stop_lon) link_station_vertex_id = "sta-%s" % link_stop_id gdb.add_edge(station_vertex_id, link_station_vertex_id, Street("link", link_length)) print ""
graph_db = args[0] assist_graph_db = args[1] osm_db = args[2] gtfs_db = args[3] graphdb = GraphDatabase( graph_db ) assistgraphdb = GraphDatabase( assist_graph_db ) osmdb = OSMDB( osm_db ) gtfsdb = GTFSDatabase( gtfs_db ) g = graphdb.incarnate() ag = assistgraphdb.incarnate() nodes = {} for id, tags, lat, lon, endnode_refs in osmdb.nodes(): nodes['osm-' + id] = (lat, lon) for id, name, lat, lon in gtfsdb.stops(): nodes['sta-' + id] = (lat, lon) os.environ['TZ'] = 'US/Pacific' time.tzset() t0s = "Tue Nov 16 07:50:30 2010" t0t = time.strptime(t0s) d0s = time.strftime('%a %b %d %Y', t0t) t0 = time.mktime(t0t) print 'search date: ', d0s print 'search time: ', time.ctime(t0), t0 wo = WalkOptions() wo.max_walk = 2000 wo.walking_overage = 0.0 wo.walking_speed = 1.0
wo.walking_overage = 0.0 wo.walking_speed = 1.0 # trimet uses 0.03 miles / 1 minute - but it uses straight line distance as well wo.transfer_penalty = 60 * 10 wo.walking_reluctance = 1.5 wo.max_transfers = 5 wo.transfer_slack = 60 * 4 wo_transit = wo print "Fetching grid from OSMDB..." grid = list(osmdb.execute("SELECT x, y, vertex FROM grid")) max_x, max_y = osmdb.execute("SELECT max(x), max(y) FROM grid").next() print "Finding unique GTFS station linking points..." station_vertices = [e[0] for e in gtfsdb.execute("SELECT DISTINCT osm_vertex FROM osm_links")] origins = ['sta-%s' % s[0] for s in gtfsdb.stops()] random.shuffle(origins) close_stations = {} for e in grid : close_stations[e[2]] = [] for o in origins : print o #spt = g.shortest_path_tree( o, None, State(1, t0), wo_foot ) #for (x, y, vertex) in grid : spt = g.shortest_path_tree( o, None, State(1, t0), wo_transit ) if spt == None : continue spt.dump_json('%s.json' % o, osmdb) print "saving image..." im = Image.new("L", (max_x, max_y)) for (x, y, vertex) in grid : v = spt.get_vertex('osm-%s'%vertex)
SAMPLE_SIZE = 200 SHOW_GS_ROUTE = True os.environ['TZ'] = 'US/Pacific' time.tzset() t0s = "Mon May 17 08:50:00 2010" t0t = time.strptime(t0s) d0s = time.strftime('%a %b %d %Y', t0t) t0 = time.mktime(t0t) print 'search date: ', d0s print 'search time: ', time.ctime(t0), t0 gtfsdb = GTFSDatabase ('/Users/andrew/devel/data/trimet.gtfsdb') gdb = GraphDatabase ('/Users/andrew/devel/data/trimet.gdb' ) g = gdb.incarnate () station_labels = [s[0] for s in gtfsdb.stops()] origins = station_labels[:] destinations = station_labels[:] random.shuffle(origins) random.shuffle(destinations) pairs = zip(origins, destinations)[:SAMPLE_SIZE] wo = WalkOptions() wo.max_walk = 2000 wo.walking_overage = 0.0 wo.walking_speed = 1.0 # trimet uses 0.03 miles / 1 minute - but it uses straight line distance as well wo.transfer_penalty = 60 * 10 wo.walking_reluctance = 1.5 wo.max_transfers = 5 wo.transfer_slack = 60 * 4