network.py 文件源码

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

项目:urbanaccess 作者: UDST 项目源码 文件源码
def _connector_edges(osm_nodes, transit_nodes, travel_speed_mph=3):
    """
    Generate the connector edges between the osm and transit edges and
    weight by travel time

    Parameters
    ----------
    osm_nodes : pandas.DataFrame
        osm nodes DataFrame
    transit_nodes : pandas.DataFrame
        transit nodes DataFrame
    travel_speed_mph : int, optional
        travel speed to use to calculate travel time across a
        distance on a edge. units are in miles per hour (MPH)
        for pedestrian travel this is assumed to be 3 MPH

    Returns
    -------
    net_connector_edges : pandas.DataFrame

    """
    start_time = time.time()

    transit_nodes['nearest_osm_node'] = _nearest_neighbor(
        osm_nodes[['x', 'y']],
        transit_nodes[['x', 'y']])

    net_connector_edges = []

    for transit_node_id, row in transit_nodes.iterrows():
        # create new edge between the node in df2 (transit)
        # and the node in openstreetmap (pedestrian)

        osm_node_id = int(row['nearest_osm_node'])
        osm_row = osm_nodes.loc[osm_node_id]

        distance = vincenty((row['y'], row['x']),
                            (osm_row['y'], osm_row['x'])).miles
        time_ped_to_transit = distance / travel_speed_mph * 60
        time_transit_to_ped = distance / travel_speed_mph * 60

        # save the edge
        net_type = 'transit to osm'
        net_connector_edges.append((transit_node_id, osm_node_id,
                                    time_transit_to_ped, net_type))
        # make the edge bi-directional
        net_type = 'osm to transit'
        net_connector_edges.append((osm_node_id, transit_node_id,
                                    time_ped_to_transit, net_type))

    net_connector_edges = pd.DataFrame(net_connector_edges,
                                       columns=["from", "to",
                                                "weight", "net_type"])

    log(
        'Connector edges between the OSM and transit network nodes '
        'successfully completed. Took {:,.2f} seconds'.format(
            time.time() - start_time))

    return net_connector_edges
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号