本文整理汇总了Python中graphserver.graphdb.GraphDatabase.commit方法的典型用法代码示例。如果您正苦于以下问题:Python GraphDatabase.commit方法的具体用法?Python GraphDatabase.commit怎么用?Python GraphDatabase.commit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphserver.graphdb.GraphDatabase
的用法示例。
在下文中一共展示了GraphDatabase.commit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from graphserver.graphdb import GraphDatabase [as 别名]
# 或者: from graphserver.graphdb.GraphDatabase import commit [as 别名]
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
# 需要导入模块: from graphserver.graphdb import GraphDatabase [as 别名]
# 或者: from graphserver.graphdb.GraphDatabase import commit [as 别名]
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()
c = gdb.get_cursor()
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(), c )
gdb.add_edge( osm_vertex_id, station_vertex_id, Link(), c )
gdb.commit()
示例3: main
# 需要导入模块: from graphserver.graphdb import GraphDatabase [as 别名]
# 或者: from graphserver.graphdb.GraphDatabase import commit [as 别名]
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"
示例4: link_osm_gtfs
# 需要导入模块: from graphserver.graphdb import GraphDatabase [as 别名]
# 或者: from graphserver.graphdb.GraphDatabase import commit [as 别名]
def link_osm_gtfs(db_conn_string, max_link_dist=150):
conn = psycopg2.connect(db_conn_string)
cursor = conn.cursor()
gdb = GraphDatabase(db_conn_string)
cursor.execute('SELECT stop_id, stop_lat, stop_lon FROM gtfs_stops')
for i, (s_label, s_lat, s_lon) in enumerate(cursor.fetchall()):
j = False
range = 0.05 # might not be the best number
cursor.execute('''SELECT id, lat, lon FROM osm_nodes WHERE endnode_refs > 1 AND lat > %s AND lat < %s AND lon > %s AND lon < %s''', ( s_lat-range, s_lat+range, s_lon-range, s_lon+range ))
nodes = cursor.fetchall()
dists = []
for n_label, n_lat, n_lon in nodes:
dists.append( distance(s_lat, s_lon, n_lat, n_lon) )
for d in dists:
if d < max_link_dist:
j = True
n_label, n_lat, n_lon = nodes[dists.index(d)]
gdb.add_edge('sta-'+s_label, 'osm-'+n_label, Street('gtfs-osm link', d))
gdb.add_edge('osm-'+n_label, 'sta-'+s_label, Street('gtfs-osm link', d))
if not j and dists: # fallback mode
d = min(dists)
n_label, n_lat, n_lon = nodes[dists.index(d)]
gdb.add_edge('sta-'+s_label, 'osm-'+n_label, Street('gtfs-osm link', d))
gdb.add_edge('osm-'+n_label, 'sta-'+s_label, Street('gtfs-osm link', d))
if not dists:
print(colored('WARNING: failed linking %s! (%s, %s)' % (s_label, s_lat, s_lon), 'yellow'))
gdb.commit()
conn.commit()
cursor.close()
示例5: main
# 需要导入模块: from graphserver.graphdb import GraphDatabase [as 别名]
# 或者: from graphserver.graphdb.GraphDatabase import commit [as 别名]
def main():
usage = """usage: python wktize_gdb.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 )
def vertex_interesting(vlabel) :
return vlabel[0:4] == 'sta-' or vlabel[0:4] == 'osm-'
def vertex_lookup(vlabel) :
if vlabel[0:4] == 'sta-' :
id, name, lat, lon = gtfsdb.stop(vlabel[4:])
vclass = 'GTFS Stop'
elif vlabel[0:4] == 'osm-' :
id, tags, lat, lon, endnode_refs = osmdb.node(vlabel[4:])
vclass = 'OSM Node'
else :
lat = None
lon = None
vclass = None
return vclass, lat, lon
c = gdb.get_cursor()
c.execute( "CREATE TABLE IF NOT EXISTS geom_vertices (label TEXT UNIQUE ON CONFLICT IGNORE, class TEXT, WKT_GEOMETRY TEXT)" )
c.execute( "CREATE TABLE IF NOT EXISTS geom_edges (class TEXT, WKT_GEOMETRY TEXT)" )
gdb.commit()
num_vertices = gdb.num_vertices()
curr_vertex = 0
for vlabel in gdb.all_vertex_labels() :
curr_vertex += 1
if curr_vertex % 1000 == 0 :
sys.stdout.write( '\rVertex %i/%i' % (curr_vertex, num_vertices) )
sys.stdout.flush()
if not vertex_interesting(vlabel) : continue
vclass, lat, lon = vertex_lookup(vlabel)
c.execute("INSERT INTO geom_vertices VALUES (?, ?, ?)", (vlabel, vclass, "POINT(%s %s)" % (lon, lat)))
gdb.commit()
print ' '
num_edges = gdb.num_edges()
curr_edge = 0
edges = gdb.execute( "SELECT vertex1, vertex2, edgetype, edgestate FROM edges" )
for vertex1, vertex2, edgetype, edgestate in edges :
curr_edge += 1
if curr_edge % 1000 == 0 :
sys.stdout.write( '\rEdge %i/%i' % (curr_edge, num_edges) )
sys.stdout.flush()
if not (vertex_interesting(vertex1) and vertex_interesting(vertex2)) : continue
vclass1, lat1, lon1 = vertex_lookup(vertex1)
vclass2, lat2, lon2 = vertex_lookup(vertex2)
c.execute("INSERT INTO geom_edges VALUES (?, ?)", (edgetype, "LINESTRING(%s %s, %s %s)" % (lon1, lat1, lon2, lat2)))
gdb.commit()
print '\nIndexing...'
gdb.execute( "CREATE INDEX IF NOT EXISTS geom_vertices_label ON geom_vertices (label)" )
gdb.execute( "CREATE INDEX IF NOT EXISTS geom_vertices_class ON geom_vertices (class)" )
gdb.execute( "CREATE INDEX IF NOT EXISTS geom_edges_class ON geom_edges (class)" )