本文整理汇总了Python中graphserver.graphdb.GraphDatabase类的典型用法代码示例。如果您正苦于以下问题:Python GraphDatabase类的具体用法?Python GraphDatabase怎么用?Python GraphDatabase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GraphDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
usage = """usage: python gdb_import_gtfs.py [options] <graphdb_filename> <gtfsdb_filename> [<agency_id>]"""
parser = OptionParser(usage=usage)
parser.add_option("-n", "--namespace", dest="namespace", default="0",
help="agency namespace")
parser.add_option("-m", "--maxtrips", dest="maxtrips", default=None, help="maximum number of trips to load")
parser.add_option("-d", "--date", dest="sample_date", default=None, help="only load transit running on a given day. YYYYMMDD" )
(options, args) = parser.parse_args()
if len(args) != 2:
parser.print_help()
exit(-1)
graphdb_filename = args[0]
gtfsdb_filename = args[1]
agency_id = args[2] if len(args)==3 else None
print "importing from gtfsdb '%s' into graphdb '%s'"%(gtfsdb_filename, graphdb_filename)
gtfsdb = GTFSDatabase( gtfsdb_filename )
gdb = GraphDatabase( graphdb_filename, overwrite=False )
maxtrips = int(options.maxtrips) if options.maxtrips else None
gdb_load_gtfsdb( gdb, options.namespace, gtfsdb, gdb.get_cursor(), agency_id, maxtrips=maxtrips, sample_date=options.sample_date)
gdb.commit()
print "done"
示例2: 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() )
示例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 gdb_import_gtfs.py [options] <graphdb_filename> <gtfsdb_filename> <agency_id>"""
parser = OptionParser(usage=usage)
parser.add_option("-n", "--namespace", dest="namespace", default="0",
help="agency namespace")
parser.add_option("-m", "--maxtrips", dest="maxtrips", default=None, help="maximum number of trips to load")
(options, args) = parser.parse_args()
if len(args) != 3:
parser.print_help()
exit(-1)
graphdb_filename = args[0]
gtfsdb_filename = args[1]
agency_id = args[2]
print "importing agency '%s' from gtfsdb '%s' into graphdb '%s'"%(agency_id, gtfsdb_filename, graphdb_filename)
gtfsdb = GTFSDatabase( gtfsdb_filename )
gdb = GraphDatabase( graphdb_filename, overwrite=False )
maxtrips = int(options.maxtrips) if options.maxtrips else None
gdb_load_gtfsdb_to_boardalight(gdb, options.namespace, gtfsdb, agency_id, gdb.get_cursor(), maxtrips=maxtrips)
gdb.commit()
print "done"
示例5: 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 )
示例6: 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())
示例7: reincarnate_ch
def reincarnate_ch(basename):
chdowndb = GraphDatabase( basename+".down.gdb" )
chupdb = GraphDatabase( basename+".up.gdb" )
upgg = chupdb.incarnate()
downgg = chdowndb.incarnate()
return ContractionHierarchy(upgg, downgg)
示例8: __init__
def __init__(self, graphdb_filename, pgosmdb_handle, pggtfsdb_handle, event_dispatch):
graphdb = GraphDatabase( graphdb_filename )
self.graph = graphdb.incarnate()
self.graph.num_agencies = 3
self.graph.numagencies = self.graph.num_agencies
self.event_dispatch = event_dispatch
self.pgosmdb = pgosmdb_handle
self.pggtfsdb = pggtfsdb_handle
self.two_way_routing = True
示例9: handle
def handle(self, *args, **options):
self.stdout.write('Loading boston.osmdb\n')
self.nodedb = osmdb.OSMDB(settings.DATA_DIR+'/boston.osmdb')
self.stdout.write('Importing Boston street network...\n')
gdb = GraphDatabase(settings.DATA_DIR+'/boston.gdb')
self.graph = gdb.incarnate()
self.stdout.write('Importing trip network...\n')
tripdb = osmdb.OSMDB(settings.DATA_DIR+'/trip_data.db')
batchgeom = []
count = 0
# For each station
for tnode in tripdb.nodes():
lat1 = float(tnode[2])
lng1 = float(tnode[3])
# get all trips departing this station
cursor = tripdb.get_cursor()
tedges = cursor.execute("select * from edges where start_nd = ?", [tnode[0]])
# For each trip
for tedge in tedges:
if tedge[3] == '':
if int(options['verbosity']) > 1:
self.stdout.write('Start and end nodes are the same.\n')
continue
dnode = tripdb.node(tedge[3])
lat2 = float(dnode[2])
lng2 = float(dnode[3])
dnode = None
if lat2 == lat1 and lng2 == lng1:
continue
geom = self._spt(lat1, lng1, lat2, lng2)
count += 1
batchgeom.append((count,geom,))
if len(batchgeom) >= options['number']:
self.dropfile(batchgeom, count, **options)
batchgeom = []
geom = None
# Don't keep a history of the execute tranactions
tedges = None
cursor = None
示例10: __init__
def __init__(self, graphdb_filename, vertex_events, edge_events, vertex_reverse_geocoders):
if os.path.exists("%s.gbin" % graphdb_filename):
self.graph = Graph()
self.graph.deserialize(graphdb_filename, os.path.exists("%s.gmm" % graphdb_filename))
else:
graphdb = GraphDatabase( graphdb_filename )
self.graph = graphdb.incarnate()
self.vertex_events = vertex_events
self.edge_events = edge_events
self.vertex_reverse_geocoders = vertex_reverse_geocoders
示例11: 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 )
示例12: process_street_graph
def process_street_graph():
OSMDB_FILENAME = "ext/osm/bartarea.sqlite"
GRAPHDB_FILENAME = "bartstreets.db"
print( "Opening OSM-DB '%s'"%OSMDB_FILENAME )
osmdb = OSMDB( OSMDB_FILENAME )
g = Graph()
compiler.load_streets_to_graph( g, osmdb, sys.stdout )
graphdb = GraphDatabase( GRAPHDB_FILENAME, overwrite=True )
graphdb.populate( g, reporter=sys.stdout )
示例13: main
def main(graph_db, gtfs_db):
graphdb = GraphDatabase( graph_db )
gtfsdb = GTFSDatabase( gtfs_db )
print "loading existing graph"
full_graph = graphdb.incarnate()
print "copying relevant vertices and edges from full graph"
min_graph = Graph()
copy_relevant_elements( min_graph, full_graph )
print "adding minimum-time transit trip edges"
add_min_transit( min_graph, gtfsdb )
print "writing out new graph to database"
min_graphdb = GraphDatabase( 'min_graph.gdb', overwrite=True )
min_graphdb.populate(min_graph)
print "DONE."
sys.exit(0)
示例14: __init__
def __init__(self, settings_filename):
settings = yaml.load( open( settings_filename ) )
self.home_point = settings['center']
# create cache of osm-node positions
self.osmdb = OSMDB( settings['osmdb_filename'] )
self.gtfsdb = GTFSDatabase( settings['gtfsdb_filename'] )
self.port = settings['port']
self.node_positions = {}
self.index = Rtree()
for node_id, tags, lat, lon in self.osmdb.nodes():
self.node_positions[node_id] = (lon,lat)
self.index.add( int(node_id), (lon,lat,lon,lat) )
# incarnate graph from graphdb
graphdb = GraphDatabase( settings['graphdb_filename'] )
self.graph = graphdb.incarnate()
示例15: main
def main():
usage = """usage: python gs_serialize.py [options] <basename> <graphdb_filename> """
parser = OptionParser(usage=usage)
parser.add_option("-m", "--memmap",
action="store_true", dest="memmap", default=False,
help="Create a memmap serialized file.")
(options, args) = parser.parse_args()
if len(args) != 2:
parser.print_help()
exit(-1)
basename, graphdb_filename = args
db = GraphDatabase(graphdb_filename)
g = db.incarnate()
g.serialize(basename, options.memmap)
print "done"