Пример #1
0
def recognize_link_position(gdf_pano: gpd.GeoDataFrame,
                            links: gpd.GeoDataFrame):
    """recognize the link near the end port or not

    Args:
        gdf_pano (gpd.GeoDataFrame): [description]
        links (gpd.GeoDataFrame): [description]

    Returns:
        [type]: [description]
    """
    link_to_end_port = links.distance(gdf_pano.iloc[-1].geometry) * 110 * 1000
    link_to_start_port = links.distance(gdf_pano.iloc[0].geometry) * 110 * 1000

    return link_to_end_port <= link_to_start_port
Пример #2
0
def request_travel_times(target_stations: gpd.GeoDataFrame,
                         origin: gpd.geoseries.GeoSeries,
                         date_time: datetime.datetime):

    times_dict = {}
    last_index = 0
    buffer = 50
    counter = 1

    router = PubTransRouter(here_app_id, here_app_code)

    while len(target_stations) > 0:

        index_farest = target_stations.distance(
            origin.geometry).sort_values(ascending=False).head(1).index
        farest_y = target_stations.loc[index_farest].geometry.centroid.y
        farest_x = target_stations.loc[index_farest].geometry.centroid.x

        pt_request = router.request_route(
            date_time, [origin.geometry.y, origin.geometry.x],
            [farest_y.iloc[0], farest_x.iloc[0]], False)
        try:

            travel_times = extract_travel_times(pt_request)

            times_dict = add_to_dict_xy(times_dict,
                                        travel_times['travel_time'].tolist(),
                                        travel_times['station'].tolist(),
                                        travel_times['y'].tolist(),
                                        travel_times['x'].tolist())

            if last_index == index_farest:
                buffer = buffer + 50
            else:
                buffer = 50

            reached_stations = find_reached_stations(travel_times,
                                                     target_stations, buffer)

            target_stations = target_stations[~target_stations['station_id'].
                                              isin(reached_stations)]

            last_index = index_farest
            counter += 1

            print(counter, '. Round')
            print(len(target_stations), ' stations left')
            if buffer > 50:
                print(buffer, ' buffer')
        except:
            print('Problem')
            print(pt_request)
            try:
                target_stations = target_stations.loc[~index_farest]
            except TypeError:
                target_stations = target_stations.iloc[0:0]

    return times_dict
Пример #3
0
def find_parent_parcel_id(
    parcel: Polygon,
    parents: gpd.GeoDataFrame,
    bldgs: gpd.GeoDataFrame,
) -> Tuple[int, Polygon]:
    """
    Given a single parcel and dataframes of candidate parent parcels
    and buildings, finds the parcel from parents that:
        1. Neighbors the target parcel geometry
        2. Minimizes dist btwn the parcel building and target parcel centroid
    NOTE: each dataframe should have 'uID' id column

    Args:
        parcel: target parcel geometry
        parents: parent geometries to match target parcel to
        bldgs: buildings dataframe used to get dist to target parcel

    Returns:
        The geometry from parents AND the index from 'uID'
    """
    assert 'uID' in parents.columns, "ERROR -- in find_parent_parcel parents should include 'uID'"
    assert 'uID' in bldgs.columns, "ERROR -- in find_parent_parcel bldgs should include 'uID'"

    # Sort buildings by distance to parcel centroid
    centroid = parcel.centroid
    bldgs = bldgs.copy()
    bldgs['dist'] = bldgs.distance(centroid)
    bldgs.sort_values(by='dist', ascending=True, inplace=True)

    # Starting w/ nearest, loop until we find a bldg
    # where the line from parent_candidate_centroid -> centroid
    # is entirely within the block
    found_match = False
    for bid in bldgs['uID'].values:
        parent = parents[parents['uID'] == bid].iloc[0]['geometry']
        nearest_pt = nearest_points(parent, parcel)
        if nearest_pt[0] == nearest_pt[1]:  # implies parcels border each other
            found_match = True
            break
    if not found_match:
        bid = None
        # NOTE: this does not imply failure, as many orphaned polys
        # are in areas w/o any buildings at all
        info(
            "Could not match orphaned parcel with centroid %s to neighboring parcel",
            centroid)

    return bid