def where_is_bicycle_lane(p): """ Define bicycle lane location for meta_data :param p: dictionary :return: tuple of two strings. Each element is either yes or no """ location = get_bicycle_lane_location(p) right = 'no' left = 'no' if location['bicycle_forward_location'] is None and location[ 'bicycle_backward_location'] is None: return 'no', 'no' if location['bicycle_forward_location'] == 'right' or location[ 'bicycle_backward_location'] == 'right': right = 'yes' if location['bicycle_forward_location'] == 'left' or location[ 'bicycle_backward_location'] == 'left': left = 'yes' return right, left
def get_lanes_from_path(path_data, nodes_dict, shape_points=16, shape_length=10.0, width=3.08, bicycle_lane_width=1.0): """ Create a lane from a path :param path_data: dictionary :param nodes_dict: dictionary :param shape_points: integer number of points to create a shaped border of a turn lane :param shape_length: float in meters: the length of the shaped portion of the border :param width: float in meters :param bicycle_lane_width: float in meters :return: list of dictionaries """ if len(path_data['nodes']) < 1: logger.warning("Path %d does not have enough nodes: %r" % (path_data['id'], path_data['nodes'])) return [] if path_data['left_border'] is None or len(path_data['left_border']) < 2: logger.warning("Path %d has an invalid left border: %r" % (path_data['id'], path_data['left_border'])) return [] if path_data['right_border'] is None or len(path_data['right_border']) < 2: logger.warning("Path %d has an invalid right border: %r" % (path_data['id'], path_data['right_border'])) return [] lanes = [] num_of_lanes = get_num_of_lanes(path_data) if 'turn:lanes' in path_data['tags']: path_data['tags']['turn:lanes'] = path_data['tags'][ 'turn:lanes'].replace('none', '').replace('None', '') lane_types = path_data['tags']['turn:lanes'].split('|') elif 'railway' in path_data['tags']: lane_types = ['rail_track'] * num_of_lanes else: lane_types = [''] * num_of_lanes lane_types = lane_types[::-1] num_of_left_lanes, num_of_right_lanes, num_of_trunk_lanes = count_lanes( path_data) bicycle_lane_location = get_bicycle_lane_location(path_data) # Construct trunk lanes left_border = copy.deepcopy(path_data['left_border']) for i in range(num_of_trunk_lanes, 0, -1): lane_type = lane_types[i + num_of_right_lanes - 1] lane_data = create_lane(path_data, nodes_dict, left_border=left_border, lane_id=str(i), lane_type=lane_type, direction=path_data['tags']['direction'], shape_points=shape_points, shape_length=shape_length, num_of_left_lanes=num_of_left_lanes, num_of_right_lanes=num_of_right_lanes, num_of_trunk_lanes=num_of_trunk_lanes, width=width) lanes.append(lane_data) left_border = lane_data['right_border'] space_for_bike_lane = get_bicycle_lane_width( bicycle_lane_location, 'right', bicycle_lane_width=bicycle_lane_width) if space_for_bike_lane > 0.0: space = create_lane(path_data, nodes_dict, left_border=left_border, lane_id='1B', lane_type='cycleway', direction=path_data['tags']['direction'], shape_points=shape_points, shape_length=shape_length, num_of_left_lanes=num_of_left_lanes, num_of_right_lanes=num_of_right_lanes, num_of_trunk_lanes=num_of_trunk_lanes, width=space_for_bike_lane) left_border = space['right_border'] # Construct right turn lanes for i in range(num_of_right_lanes, 0, -1): lane_data = create_lane(path_data, nodes_dict, left_border=left_border, lane_id=str(i), lane_type='right', direction=path_data['tags']['direction'], shape_points=shape_points, shape_length=shape_length, num_of_left_lanes=num_of_left_lanes, num_of_right_lanes=num_of_right_lanes, num_of_trunk_lanes=num_of_trunk_lanes, width=width) lanes.append(lane_data) left_border = lane_data['right_border'] right_border = copy.deepcopy(path_data['left_border']) right_shaped_border = right_border space_for_bike_lane = get_bicycle_lane_width( bicycle_lane_location, 'left', bicycle_lane_width=bicycle_lane_width) if space_for_bike_lane > 0.0: space = create_lane(path_data, nodes_dict, right_border=right_border, lane_id='1B', lane_type='cycleway', direction=path_data['tags']['direction'], right_shaped_border=right_shaped_border, shape_points=shape_points, shape_length=shape_length, num_of_left_lanes=num_of_left_lanes, num_of_right_lanes=num_of_right_lanes, num_of_trunk_lanes=num_of_trunk_lanes, width=space_for_bike_lane) right_border = space['left_border'] right_shaped_border = space['left_shaped_border'] # Construct left turn lanes for i in range(num_of_left_lanes): lane_data = create_lane(path_data, nodes_dict, right_border=right_border, lane_id=str(i + 1), lane_type='left', direction=path_data['tags']['direction'], right_shaped_border=right_shaped_border, shape_points=shape_points, shape_length=shape_length, num_of_left_lanes=num_of_left_lanes, num_of_right_lanes=num_of_right_lanes, num_of_trunk_lanes=num_of_trunk_lanes, width=width) lanes.append(lane_data) right_border = lane_data['left_border'] right_shaped_border = lane_data['left_shaped_border'] return lanes
def get_bicycle_lanes_from_path(path_data, nodes_dict, width=1.0): if len(path_data['nodes']) < 2: return [] if key_value_check([('bicycle', 'no')], path_data): return [] lanes = [] if is_shared(path_data): lane_data = create_lane(path_data, nodes_dict, right_border=path_data['right_border'], lane_id='1B', lane_type='cycleway', direction=path_data['tags']['direction'], width=width) lanes.append(lane_data) else: bicycle_lane_location = get_bicycle_lane_location(path_data) fl = bicycle_lane_location['bicycle_forward_location'] bl = bicycle_lane_location['bicycle_backward_location'] if fl == 'right' and bl == 'right': backward_lane_data = create_lane( path_data, nodes_dict, left_border=path_data['right_border'], lane_id='1B', lane_type='cycleway', direction=reverse_direction(path_data['tags']['direction']), width=width) forward_lane_data = create_lane( path_data, nodes_dict, left_border=backward_lane_data['right_border'], lane_id='1B', lane_type='cycleway', direction=path_data['tags']['direction'], width=width) lanes.append(forward_lane_data) lanes.append(backward_lane_data) elif fl == 'right' and bl == 'left': backward_lane_data = create_lane( path_data, nodes_dict, right_border=path_data['left_border'], lane_id='1B', lane_type='cycleway', direction=reverse_direction(path_data['tags']['direction']), width=width) forward_lane_data = create_lane( path_data, nodes_dict, left_border=path_data['right_border'], lane_id='1B', lane_type='cycleway', direction=path_data['tags']['direction'], width=width) lanes.append(forward_lane_data) lanes.append(backward_lane_data) elif fl == 'left' and bl == 'left': forward_lane_data = create_lane( path_data, nodes_dict, right_border=path_data['left_border'], lane_id='1B', lane_type='cycleway', direction=path_data['tags']['direction'], width=width) backward_lane_data = create_lane( path_data, nodes_dict, right_border=forward_lane_data['left_border'], lane_id='1B', lane_type='cycleway', direction=reverse_direction(path_data['tags']['direction']), width=width) lanes.append(forward_lane_data) lanes.append(backward_lane_data) elif fl == 'left' and bl == 'right': forward_lane_data = create_lane( path_data, nodes_dict, right_border=path_data['left_border'], lane_id='1B', lane_type='cycleway', direction=path_data['tags']['direction'], width=width) backward_lane_data = create_lane( path_data, nodes_dict, left_border=path_data['right_border'], lane_id='1B', lane_type='cycleway', direction=reverse_direction(path_data['tags']['direction']), width=width) lanes.append(forward_lane_data) lanes.append(backward_lane_data) elif fl == 'left' and bl is None: forward_lane_data = create_lane( path_data, nodes_dict, right_border=path_data['left_border'], lane_id='1B', lane_type='cycleway', direction=path_data['tags']['direction'], width=width) lanes.append(forward_lane_data) elif fl == 'right' and bl is None: forward_lane_data = create_lane( path_data, nodes_dict, left_border=path_data['right_border'], lane_id='1B', lane_type='cycleway', direction=path_data['tags']['direction'], width=width) lanes.append(forward_lane_data) elif fl is None and bl == 'right': backward_lane_data = create_lane( path_data, nodes_dict, left_border=path_data['right_border'], lane_id='1B', lane_type='cycleway', direction=reverse_direction(path_data['tags']['direction']), width=width) lanes.append(backward_lane_data) elif fl is None and bl == 'left': backward_lane_data = create_lane( path_data, nodes_dict, right_border=path_data['left_border'], lane_id='1B', lane_type='cycleway', direction=reverse_direction(path_data['tags']['direction']), width=width) lanes.append(backward_lane_data) return lanes
def create_lane(p, nodes_dict, left_border=None, right_border=None, right_shaped_border=None, lane_id='1', lane_type='', direction='undefined', width=3.048, shape_points=16, shape_length=10.0, num_of_left_lanes=0, num_of_right_lanes=0, num_of_trunk_lanes=1, crosswalk_width=1.82): """ Create a lane from a path :param p: :param nodes_dict: :param left_border: :param right_border: :param right_shaped_border: :param lane_id: :param lane_type: :param direction: :param width: :param shape_points: :param shape_length: :param num_of_left_lanes: :param num_of_right_lanes: :param num_of_trunk_lanes: :param crosswalk_width: :return: """ lane_data = { 'lane_id': str(lane_id), 'path_id': p['id'], 'path': p, 'left_border': copy.deepcopy(left_border), 'lane_type': lane_type, 'direction': direction, 'width': width, 'shape_points': shape_points, 'shape_length': shape_length, 'num_of_left_lanes': num_of_left_lanes, 'num_of_right_lanes': num_of_right_lanes, 'num_of_trunk_lanes': num_of_trunk_lanes, 'crosswalk_width': crosswalk_width } if lane_type == 'cycleway': bicycle_lane_location = get_bicycle_lane_location(p) lane_data['bicycle_forward_location'] = bicycle_lane_location[ 'bicycle_forward_location'] lane_data['bicycle_backward_location'] = bicycle_lane_location[ 'bicycle_backward_location'] for x in p['tags']: lane_data[x] = p['tags'][x] if lane_type == 'left': lane_data['lane_id'] = str(lane_id) + 'L' elif lane_type == 'right': lane_data['lane_id'] = str(lane_id) + 'R' if 'name' in p['tags']: name = p['tags']['name'] elif 'highway' in p['tags'] and 'link' in p['tags']['highway']: name = p['tags']['highway'] else: name = 'no_name' lane_data['name'] = name lane_data['nodes'] = p['nodes'] lane_data['nodes_coordinates'] = [(nodes_dict[n]['x'], nodes_dict[n]['y']) for n in lane_data['nodes']] lane_data['right_shaped_border'] = None lane_data['left_shaped_border'] = None if right_border is None: lane_data['left_border'] = copy.deepcopy(left_border) lane_data['right_border'] = shift_list_of_nodes( left_border, [width] * len(left_border)) elif left_border is None: lane_data['right_border'] = copy.deepcopy(right_border) lane_data['left_border'] = shift_list_of_nodes(right_border, [-width] * len(right_border)) if 'L' in lane_data['lane_id']: right_border_with_inserted_points = add_incremental_points( right_border, n=shape_points, l=shape_length) delta_len = len(right_border_with_inserted_points) - len( right_border) shaped_widths = get_shaped_lane_width(-width, n=shape_points) width_list = shaped_widths[:delta_len] + [-width ] * len(right_border) if lane_data['lane_id'] == '1L': lane_data['right_shaped_border'] = copy.deepcopy( lane_data['right_border']) lane_data['left_shaped_border'] = shift_list_of_nodes( right_border_with_inserted_points, width_list) elif right_shaped_border is not None: lane_data['right_shaped_border'] = copy.deepcopy( right_shaped_border) lane_data['left_shaped_border'] = shift_list_of_nodes( right_shaped_border, width_list, direction_reference=lane_data['right_border']) else: lane_data['right_border'] = copy.deepcopy(right_border) lane_data['left_border'] = copy.deepcopy(left_border) if 'L' not in lane_data['lane_id']: lane_data['right_shaped_border'] = None lane_data['left_shaped_border'] = None lane_data['median'] = shift_list_of_nodes(lane_data['left_border'], [width / 2.0] * len(lane_data['left_border'])) lane_data['length'] = get_border_length(lane_data['median']) insert_referenced_nodes(lane_data, nodes_dict) return lane_data