当前位置: 首页>>代码示例>>Python>>正文


Python GraphDatabase.add_edge方法代码示例

本文整理汇总了Python中graphserver.graphdb.GraphDatabase.add_edge方法的典型用法代码示例。如果您正苦于以下问题:Python GraphDatabase.add_edge方法的具体用法?Python GraphDatabase.add_edge怎么用?Python GraphDatabase.add_edge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graphserver.graphdb.GraphDatabase的用法示例。


在下文中一共展示了GraphDatabase.add_edge方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from graphserver.graphdb import GraphDatabase [as 别名]
# 或者: from graphserver.graphdb.GraphDatabase import add_edge [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()

    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() )
开发者ID:bcavagnolo,项目名称:Bikesy-Backend,代码行数:33,代码来源:gdb_link_osm_gtfs.py

示例2: main

# 需要导入模块: from graphserver.graphdb import GraphDatabase [as 别名]
# 或者: from graphserver.graphdb.GraphDatabase import add_edge [as 别名]
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 ""
开发者ID:Jamie5,项目名称:graphserver,代码行数:37,代码来源:gdb_link_gtfs_gtfs.py

示例3: link_osm_gtfs

# 需要导入模块: from graphserver.graphdb import GraphDatabase [as 别名]
# 或者: from graphserver.graphdb.GraphDatabase import add_edge [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()
开发者ID:MaxBo,项目名称:graphserver,代码行数:46,代码来源:import_base_data.py

示例4: main

# 需要导入模块: from graphserver.graphdb import GraphDatabase [as 别名]
# 或者: from graphserver.graphdb.GraphDatabase import add_edge [as 别名]
def main():
    if len(argv) < 2:
        print "usage: python import_ned.py graphdb_filename profiledb_filename"
        return
        
    graphdb_filename = argv[1]
    profiledb_filename = argv[2]
        
    gdb = GraphDatabase( graphdb_filename )
    profiledb = ProfileDB( profiledb_filename )
    
    n = gdb.num_edges()

    for i, (oid, vertex1, vertex2, edge) in enumerate( list(gdb.all_edges(include_oid=True)) ):
        if i%500==0: print "%s/%s"%(i,n)
        
        if isinstance( edge, Street ):
            rise, fall = get_rise_and_fall( profiledb.get( edge.name ) )
            edge.rise = rise
            edge.fall = fall
            
            gdb.remove_edge( oid )
            gdb.add_edge( vertex1, vertex2, edge )
开发者ID:Jamie5,项目名称:graphserver,代码行数:25,代码来源:gdb_import_ned.py


注:本文中的graphserver.graphdb.GraphDatabase.add_edge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。