本文整理匯總了Python中graphserver.ext.gtfs.gtfsdb.GTFSDatabase類的典型用法代碼示例。如果您正苦於以下問題:Python GTFSDatabase類的具體用法?Python GTFSDatabase怎麽用?Python GTFSDatabase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了GTFSDatabase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
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() )
示例2: process_transit_graph
def process_transit_graph(graphdb_filename, gtfsdb_filenames, osmdb_filename=None, profiledb_filename=None, agency_id=None, link_stations=False, slogs={}):
g = Graph()
if profiledb_filename:
print( "Opening ProfileDB '%s'"%profiledb_filename )
profiledb = ProfileDB( profiledb_filename )
else:
print( "No ProfileDB supplied" )
profiledb = None
if osmdb_filename:
# Load osmdb ===============================
print( "Opening OSM-DB '%s'"%osmdb_filename )
osmdb = OSMDB( osmdb_filename )
compiler.load_streets_to_graph( g, osmdb, profiledb, slogs, reporter=sys.stdout )
# Load gtfsdb ==============================
for i, gtfsdb_filename in enumerate(gtfsdb_filenames):
gtfsdb = GTFSDatabase( gtfsdb_filename )
service_ids = [x.encode("ascii") for x in gtfsdb.service_ids()]
compiler.load_gtfsdb_to_boardalight_graph(g, str(i), gtfsdb, agency_id=agency_id, service_ids=service_ids)
if osmdb_filename:
compiler.load_transit_street_links_to_graph( g, osmdb, gtfsdb, reporter=sys.stdout )
if link_stations:
compiler.link_nearby_stops( g, gtfsdb )
# Export to graphdb ========================
graphdb = GraphDatabase( graphdb_filename, overwrite=True )
graphdb.populate( g, reporter=sys.stdout )
示例3: main
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 ""
示例4: main
def main():
usage = """usage: python dedupe.py <graphdb_filename>"""
parser = OptionParser(usage=usage)
(options, args) = parser.parse_args()
if len(args) != 1:
parser.print_help()
exit(-1)
graphdb_filename = args[0]
gtfsdb = GTFSDatabase( graphdb_filename )
query = """
SELECT count(*), monday, tuesday, wednesday, thursday, friday, saturday, sunday, start_date, end_date
FROM calendar
GROUP BY monday, tuesday, wednesday, thursday, friday, saturday, sunday, start_date, end_date"""
duped_periods = gtfsdb.execute( query )
equivilants = []
for count, m,t,w,th,f,s,su,start_date,end_date in duped_periods:
# no need to check for dupes if there's only one
if count==1:
continue
#print count, m, t, w, th, f, s, su, start_date, end_date
# get service_ids for this dow/start_date/end_date combination
service_ids = [x[0] for x in list( gtfsdb.execute( "SELECT service_id FROM calendar where monday=? and tuesday=? and wednesday=? and thursday=? and friday=? and saturday=? and sunday=? and start_date=? and end_date=?", (m,t,w,th,f,s,su,start_date,end_date) ) ) ]
# group by service periods with the same set of exceptions
exception_set_grouper = {}
for service_id in service_ids:
exception_set = list(gtfsdb.execute( "SELECT date, exception_type FROM calendar_dates WHERE service_id=?", (service_id,) ) )
exception_set.sort()
exception_set = tuple(exception_set)
exception_set_grouper[exception_set] = exception_set_grouper.get(exception_set,[])
exception_set_grouper[exception_set].append( service_id )
# extend list of equivilants
for i, exception_set_group in enumerate( exception_set_grouper.values() ):
equivilants.append( ("%d%d%d%d%d%d%d-%s-%s-%d"%(m,t,w,th,f,s,su,start_date,end_date,i), exception_set_group) )
for new_name, old_names in equivilants:
for old_name in old_names:
print old_name, new_name
c = gtfsdb.conn.cursor()
c.execute( "UPDATE calendar SET service_id=? WHERE service_id=?", (new_name, old_name) )
c.execute( "UPDATE calendar_dates SET service_id=? WHERE service_id=?", (new_name, old_name) )
c.execute( "UPDATE trips SET service_id=? WHERE service_id=?", (new_name, old_name) )
gtfsdb.conn.commit()
c.close()
示例5: importGtfsWrapper
def importGtfsWrapper(gtfs_filename, db_conn_string):
gdb = GraphDatabase( db_conn_string, overwrite=False )
gtfsdb = GTFSDatabase( db_conn_string, overwrite=True )
gtfsdb.load_gtfs( gtfs_filename )
gdb_load_gtfsdb( gdb, 1, gtfsdb, gdb.get_cursor())
示例6: process_transit_graph
def process_transit_graph(gtfsdb_filename, agency_id, graphdb_filename, link=False):
gtfsdb = GTFSDatabase( gtfsdb_filename )
g = Graph()
service_ids = [x.encode("ascii") for x in gtfsdb.service_ids()]
compiler.load_gtfsdb_to_boardalight_graph(g, gtfsdb, agency_id=agency_id, service_ids=service_ids)
if link:
compiler.link_nearby_stops( g, gtfsdb )
graphdb = GraphDatabase( graphdb_filename, overwrite=True )
graphdb.populate( g, reporter=sys.stdout )
示例7: __init__
class DescribeCrossingAtAlightEvent:
def __init__(self, gtfsdb_filename, timezone_name="America/Los_Angeles"):
self.gtfsdb = GTFSDatabase( gtfsdb_filename )
self.timezone_name = timezone_name
@staticmethod
def applies_to(vertex1, edge, vertex2):
# if the stop_sequence is the same before and after the TripAlight was crossed, it means the algorithm crossed in the forward
# direction - because the stop_sequence doesn't get set on a forward alight. If this is true then this is the appropriate time
# to describe the transit trip that led to this alighting
return edge is not None \
and isinstance(edge.payload, graphserver.core.TripAlight) \
and vertex1.state.stop_sequence == vertex2.state.stop_sequence
def __call__(self, vertex1, edge, vertex2, context):
stop_sequence_of_boarding = vertex1.state.stop_sequence
trip_id = vertex1.state.trip_id
alighting_trip_id, alighting_time, alighting_stop_sequences = edge.payload.get_alighting_by_trip_id( trip_id )
what = "Ride trip %s from stop_seq %s to stop_seq %s"%(trip_id, vertex1.state.stop_sequence, alighting_stop_sequences)
where = None
when = None
geom = self.gtfsdb.shape_between( trip_id, vertex1.state.stop_sequence, alighting_stop_sequences )
return NarrativeEvent(what, where, when, geom)
示例8: main
def main():
gtfsdb = GTFSDatabase( "data/washingtondc.gtfsdb" )
osmdb = OSMDB( "data/washingtondc.osmdb" )
ll,bb,rr,tt = list(gtfsdb.execute( "SELECT min(stop_lon), min(stop_lat), max(stop_lon), max(stop_lat) FROM stops" ))[0]
from prender import processing
mr = processing.MapRenderer()
mr.start(ll,bb,rr,tt,4000) #left,bottom,right,top,width
mr.smooth()
mr.strokeWeight(0.000001)
mr.background(255,255,255)
mr.stroke(128,128,128)
render_osmdb(osmdb, mr)
mr.stroke(0,0,0)
render_gtfsdb(gtfsdb, mr)
mr.saveLocal("map.png")
mr.stop()
示例9: process_transit_street_graph
def process_transit_street_graph(graphdb_filename, gtfsdb_filename, osmdb_filename, agency_id=None):
g = Graph()
# Load osmdb ===============================
print( "Opening OSM-DB '%s'"%osmdb_filename )
osmdb = OSMDB( osmdb_filename )
compiler.load_streets_to_graph( g, osmdb, sys.stdout )
# Load gtfsdb ==============================
for i, gtfsdb_filename in enumerate(gtfsdb_filenames):
gtfsdb = GTFSDatabase( gtfsdb_filename )
service_ids = [x.encode("ascii") for x in gtfsdb.service_ids()]
compiler.load_gtfsdb_to_boardalight_graph(g, str(i), gtfsdb, agency_id=agency_id, service_ids=service_ids)
compiler.load_transit_street_links_to_graph( g, osmdb, gtfsdb, reporter=sys.stdout )
# Export to graphdb ========================
graphdb = GraphDatabase( graphdb_filename, overwrite=True )
graphdb.populate( g, reporter=sys.stdout )
示例10: len
# requires graphserver to be installed
from graphserver.ext.gtfs.gtfsdb import GTFSDatabase
verbose = False
RADIUS = 2000 # meters
OBSTRUCTION = 1.3 #factor to expand straight-line distance
range_lat = RADIUS / 111111.111
if len(sys.argv) < 2 :
print 'usage: transfers.py infile.gtfsdb [verbose]'
exit(1)
gtfsdb_file = sys.argv[1]
try :
with open(gtfsdb_file) as f :
db = GTFSDatabase(gtfsdb_file)
except IOError as e :
print 'gtfsdb file "%s" cannot be opened' % gtfsdb_file
exit(1)
if len(sys.argv) > 2 and sys.argv[2] == "verbose" :
verbose = True
# we we are interested in all routes available on each stop
all_query = """select stops.stop_id, stops.stop_name, stops.stop_lat, stops.stop_lon, routes from
(select stop_id, group_concat(route_id, ',') as routes
from (select distinct route_id, stop_id from trips, stop_times
where trips.trip_id = stop_times.trip_id) as x
group by stop_id) as y, stops where y.stop_id = stops.stop_id;"""
near_query = """
select stop_id, stop_name, stop_lat, stop_lon from stops where
示例11: GTFSDatabase
import numpy as np
import random
import time
import httplib
from graphserver.ext.gtfs.gtfsdb import GTFSDatabase
from graphserver.graphdb import GraphDatabase
TRIP_TIME = '08:00AM'
TRIP_DATE = '01-29-2010'
URL_FORMAT = '/ws/V1/trips/tripplanner/maxIntineraries/1/fromcoord/%s/tocoord/%s/date/%s/time/%s/walk/0.999/appId/6AC697CF5EB8719DB6F3AEF0B'
print 'search date: ', TRIP_DATE
print 'search time: ', TRIP_TIME
gtfsdb = GTFSDatabase ('../data/pdx/trimet-20100117.gtfsdb')
npz = np.load('../data/pdx/trimet-20100117.od_matrix.npz')
station_labels = npz['station_labels']
matrix = npz['matrix'].astype(np.int32)
station_idx = dict( zip(station_labels, range(len(station_labels))) )
origins = list(station_labels)
destinations = origins[:] # copy 1 level
random.shuffle(origins)
random.shuffle(destinations)
pairs = zip(origins, destinations)
errors = []
示例12: open
#!/usr/bin/python
import sys, struct
from struct import Struct
# requires graphserver to be installed
from graphserver.ext.gtfs.gtfsdb import GTFSDatabase
from datetime import timedelta, date
gtfsdb_file = sys.argv[1]
try:
with open(gtfsdb_file) as f:
db = GTFSDatabase(gtfsdb_file)
except IOError as e:
print "gtfsdb file %s cannot be opened" % gtfsdb_file
exit(1)
# display number of active services to spot the usable period for this feed
dfrom, dto = db.date_range()
d = dfrom
while d <= dto:
active_sids = db.service_periods(d)
print d, len(active_sids)
d += timedelta(days=1)
示例13: GTFSDatabase
from graphserver.ext.gtfs.gtfsdb import GTFSDatabase
from graphserver.graphdb import GraphDatabase
from graphserver.core import Graph, Street, State, WalkOptions
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
示例14: GTFSDatabase
#
import numpy as np
import pylab as pl
import random
import time
import httplib
from graphserver.ext.gtfs.gtfsdb import GTFSDatabase
from graphserver.graphdb import GraphDatabase
TRIP_TIME = '08:00AM'
TRIP_DATE = '01-29-2010'
URL_FORMAT = '/ws/V1/trips/tripplanner/maxIntineraries/1/fromcoord/%s/tocoord/%s/date/%s/time/%s/appId/6AC697CF5EB8719DB6F3AEF0B'
gtfsdb = GTFSDatabase ('../data/pdx/trimet-20100117.gtfsdb')
npz = np.load('../data/pdx/trimet-20100117.od_matrix.npz')
station_labels = npz['station_labels']
station_coords = npz['station_coords']
grid_dim = npz['grid_dim']
matrix = npz['matrix'].astype(np.int32)
matrix = (matrix + matrix.T) / 2
r = np.load('results/pdx-5d-1000i/result.npy')
station_idx = dict( zip(station_labels, range(len(station_labels))) )
origins = list(zip(station_labels, np.round(station_coords).astype(np.int32)))
destinations = origins[:] # copy 1 level
示例15: len
#!/usr/bin/python
import sys, struct
# requires graphserver to be installed
from graphserver.ext.gtfs.gtfsdb import GTFSDatabase
if len(sys.argv) != 2:
print "usage: datecheck.py inputfile.gtfsdb"
exit(1)
else:
gtfsdb_file = sys.argv[1]
try:
with open(gtfsdb_file) as f:
db = GTFSDatabase(gtfsdb_file)
except IOError as e:
print "gtfsdb file %s cannot be opened" % gtfsdb_file
exit(1)
# check that all routes gs reports running are actually running on each day
for line in sys.stdin.readlines():
trip_id, fromid, fromtime, toid, totime = line.split()
if trip_id == "walk":
continue
service_id = list(db.execute("select service_id from trips where trip_id = ?", (trip_id,)))[0][0]
print trip_id, "___", service_id
# and date > 20130415 and date < 20130420
for line in db.execute(
"select date from calendar_dates where service_id = ? and date = 20130417 order by date", (service_id,)
):