Beispiel #1
0
def get_right_turn_guideways(all_lanes):
    """
    Create a list of right turn guideways for lanes having an additional link to the destination
    :param all_lanes: list of dictionaries
    :return: list of dictionaries
    """

    logger.info('Starting right guideways')
    guideways = []
    for origin_lane in all_lanes:
        if is_right_turn_allowed(origin_lane, all_lanes):
            logger.debug('Origin Lane ' + dictionary_to_log(origin_lane))
            try:
                guideway_data = create_right_turn_guideway(
                    origin_lane, all_lanes)
                set_guideway_id(guideway_data)
            except Exception as e:
                logger.exception(e)
                guideway_data = None

            if guideway_data is not None:
                logger.debug('Guideway ' + dictionary_to_log(guideway_data))
                guideways.append(guideway_data)

    logger.info('Created %d guideways' % len(guideways))
    return guideways
Beispiel #2
0
def get_through_guideways(all_lanes):
    """
    Create through guideways from a list of merged lanes
    :param all_lanes: list of dictionaries
    :return: list of dictionaries
    """

    logger.info('Starting through guideways')
    guideways = []
    for origin_lane in all_lanes:
        if is_through_allowed(origin_lane):
            logger.debug('Origin Lane ' + dictionary_to_log(origin_lane))
            destination_lane = get_destination_lane(origin_lane, all_lanes)
            if destination_lane is not None:
                logger.debug('Destin Lane ' +
                             dictionary_to_log(destination_lane))
                try:
                    guideway_data = get_through_guideway(
                        origin_lane, destination_lane)
                    set_guideway_id(guideway_data)
                    guideways.append(guideway_data)
                    logger.debug('Guideway ' +
                                 dictionary_to_log(guideway_data))
                except Exception as e:
                    logger.exception(e)

    logger.info('Created %d guideways' % len(guideways))
    return guideways
Beispiel #3
0
def get_left_turn_guideways(all_lanes, nodes_dict):
    """
    Compile a list of guideways for all legal left turns
    :param all_lanes: list of dictionaries
    :param nodes_dict: dictionary
    :return: list of dictionaries
    """
    logger.info('Starting left turn guideways')
    guideways = []
    for origin_lane in all_lanes:
        if is_left_turn_allowed(origin_lane):
            logger.debug('Origin Lane ' + dictionary_to_log(origin_lane))
            for destination_lane in get_destination_lanes_for_left_turn(
                    origin_lane, all_lanes, nodes_dict):
                logger.debug('Destin Lane ' +
                             dictionary_to_log(destination_lane))
                try:
                    guideway_data = get_direct_turn_guideway(origin_lane,
                                                             destination_lane,
                                                             all_lanes,
                                                             turn_type='left')
                    set_guideway_id(guideway_data)
                except Exception as e:
                    logger.exception(e)
                    guideway_data = None

                if guideway_data is not None:
                    logger.debug('Guideway ' +
                                 dictionary_to_log(guideway_data))
                    guideways.append(guideway_data)

    logger.info('Created %d guideways' % len(guideways))
    return guideways
def get_bicycle_left_turn_guideways(all_lanes, nodes_dict):
    """
    Compile a list of bicycle guideways for all legal left turns
    :param all_lanes: list of dictionaries
    :param nodes_dict: dictionary
    :return: list of dictionaries
    """
    logger.info('Starting bicycle left turn guideways')
    guideways = []
    through_guideways = get_through_guideways(all_lanes)

    for origin_lane in all_lanes:
        if is_left_turn_allowed(origin_lane):
            for destination_lane in get_destination_lanes_for_left_turn(
                    origin_lane, all_lanes, nodes_dict):
                origin_candidates = [
                    g for g in through_guideways
                    if g['origin_lane']['id'] == origin_lane['id']
                ]
                destination_candidates = [
                    g for g in through_guideways
                    if g['destination_lane']['id'] == destination_lane['id']
                ]
                if origin_candidates and destination_candidates:
                    logger.debug('Origin Lane ' +
                                 dictionary_to_log(origin_candidates[0]))
                    logger.debug('Destin Lane ' +
                                 dictionary_to_log(destination_candidates[0]))
                    try:
                        guideway_data = get_bicycle_left_guideway(
                            origin_lane, destination_lane,
                            origin_candidates[0], destination_candidates[0])
                        set_guideway_id(guideway_data)
                    except Exception as e:
                        logger.exception(e)
                        guideway_data = None

                else:
                    guideway_data = None

                if guideway_data is not None \
                        and guideway_data['left_border'] is not None \
                        and guideway_data['median'] is not None \
                        and guideway_data['right_border'] is not None:
                    logger.debug('Guideway ' +
                                 dictionary_to_log(guideway_data))
                    guideways.append(guideway_data)

    logger.info('Created %d guideways' % len(guideways))
    return guideways
Beispiel #5
0
def get_u_turn_guideways(all_lanes, x_data):
    """
    Compile a list of bicycle guideways for all legal u-turns
    :param all_lanes: list of dictionaries
    :param x_data: intersection dictionary
    :return: list of dictionaries
    """

    logger.info('Starting U-turn guideways')
    guideways = []

    for origin_lane in all_lanes:
        if is_u_turn_allowed(origin_lane, x_data):
            logger.debug('Origin Lane ' + dictionary_to_log(origin_lane))
            for destination_lane in get_destination_lanes_for_u_turn(
                    origin_lane, all_lanes):
                logger.debug('Destin Lane ' +
                             dictionary_to_log(destination_lane))
                try:
                    guideway_data = get_u_turn_guideway(
                        origin_lane, destination_lane, all_lanes)
                    set_guideway_id(guideway_data)
                except Exception as e:
                    logger.exception(e)
                    guideway_data = None

                if guideway_data is not None \
                        and guideway_data['left_border'] is not None \
                        and guideway_data['median'] is not None \
                        and guideway_data['right_border'] is not None:
                    logger.debug('Guideway ' +
                                 dictionary_to_log(guideway_data))
                    guideways.append(guideway_data)

    logger.info('Created %d guideways' % len(guideways))
    return guideways
def create_intersection(street_tuple, data, size=500.0, crop_radius=150.0):
    """
    Create dictionary of intersection data.  The input data can be either city data or selection data
    :param street_tuple: tuple of strings
    :param data: dictionary
    :param size: float in meters: initial size of osm data
    :param crop_radius: float in meters: the data within the initial size will be cropped to the specified radius
    :return: dictionary
    """
    x_nodes = select_close_nodes(
        data['nodes'], get_intersection_nodes(data['paths'], street_tuple))

    if x_nodes is None or len(x_nodes) < 1:
        logger.error(
            'Unable to find common nodes referenced in all streets %r' %
            ', '.join(street_tuple))
        return None

    u, v = get_center(x_nodes, data['nodes'])

    if data['raw_data'] is None:
        north, south, east, west = get_box(u, v, size=size)
    else:
        north, south, east, west = get_box_from_xml(
            data['raw_data'][0]['bounds'])
    x_data = {
        'city': data['name'],
        'from_file': data['from_file'],
        'streets': street_tuple,
        'center_x': u,
        'center_y': v,
        'north': north,
        'south': south,
        'east': east,
        'west': west,
        'size': size,
        'crop_radius': crop_radius,
        'x_nodes': x_nodes,
        'nodes': {}
    }

    logger.info('Creating Intersection ' + dictionary_to_log(x_data))
    return x_data