osm_transfers.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:gtfspy 作者: CxAalto 项目源码 文件源码
def create_walk_network_from_osm(osm_file):
    walk_network = networkx.Graph()
    assert (os.path.exists(osm_file))
    ways = []
    for i, entity in enumerate(parse_file(osm_file)):
        if isinstance(entity, Node):
            walk_network.add_node(entity.id, lat=entity.lat, lon=entity.lon)
        elif isinstance(entity, Way):
            if "highway" in entity.tags:
                if entity.tags["highway"] in OSM_HIGHWAY_WALK_TAGS:
                    ways.append(entity)
    for way in ways:
        walk_network.add_path(way.nodes)
    del ways

    # Remove all singleton nodes (note that taking the giant component does not necessarily provide proper results.
    for node, degree in walk_network.degree().items():
        if degree is 0:
            walk_network.remove_node(node)

    node_lats = networkx.get_node_attributes(walk_network, 'lat')
    node_lons = networkx.get_node_attributes(walk_network, 'lon')
    for source, dest, data in walk_network.edges(data=True):
        data["distance"] = wgs84_distance(node_lats[source],
                                          node_lons[source],
                                          node_lats[dest],
                                          node_lons[dest])
    return walk_network
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号