def remove_intersecting_portion_from_streets(street_data, streets): """ Cut out intersecting portions of streets with the specified street. Reserved for future use :param street_data: street dictionary :param streets: list of dictionaries :return: list of dictionaries """ streets_without_intersection = [] for st in streets: if street_data['name'] == st['name'] or 'link' in st['name']: continue shorten_street = copy.deepcopy(st) right_border = shorten_border_for_crosswalk(st['right_border'], st['name'], streets, crosswalk_width=20, destination='to_intersection' ) left_border = shorten_border_for_crosswalk(st['left_border'], st['name'], streets, crosswalk_width=20, destination='to_intersection' ) shorten_street['right_border'] = extend_origin_border(right_border, relative=True) shorten_street['left_border'] = extend_origin_border(left_border, relative=True) streets_without_intersection.append(shorten_street) return streets_without_intersection
def get_simulated_crosswalk(street_data, streets, width=1.8): """ Construct a simulated crosswalk :param street_data: street dictionary :param streets: list of dictionaries :param width: float, crosswalk width in meters :return: crosswalk dictionary """ right_border = shorten_border_for_crosswalk(street_data['right_border'], street_data['name'], streets, crosswalk_width=2, destination='to_intersection', exclude_parallel=False) left_border = shorten_border_for_crosswalk(street_data['left_border'], street_data['name'], streets, crosswalk_width=2, destination='to_intersection', exclude_parallel=False) right_border2 = shorten_border_for_crosswalk(street_data['right_border'], street_data['name'], streets, crosswalk_width=2 + width, destination='to_intersection', exclude_parallel=False) left_border2 = shorten_border_for_crosswalk(street_data['left_border'], street_data['name'], streets, crosswalk_width=2 + width, destination='to_intersection', exclude_parallel=False) crosswalk = { 'lane_id': '1C', 'name': street_data['name'], 'simulated': 'yes', 'right_border': [right_border[-1], left_border[-1]], 'left_border': [right_border2[-1], left_border2[-1]], 'median': shift_vector([right_border[-1], left_border[-1]], -width / 2.0), 'path_id': 0, 'path': [], 'lane_type': 'crosswalk', 'direction': 'undefined', 'nodes': [], 'nodes_coordinates': [], 'width': width, 'type': 'footway' } bearing = get_compass(crosswalk['right_border'][0], crosswalk['right_border'][-1]) crosswalk['bearing'] = bearing crosswalk['compass'] = get_compass_rhumb(bearing), crosswalk['length'] = get_border_length(crosswalk['median']) logger.debug('Created crosswalk for street %s %s' % (street_data['name'], street_data['compass'])) return crosswalk
def get_u_turn_border(origin_lane, destination_lane, all_lanes, border_type='left'): """ Construct a border of a u-turn guideway :param origin_lane: dictionary :param destination_lane: dictionary :param all_lanes: list of dictionaries :param border_type: string: either 'left' or 'right' or 'median' :return: list of coordinates """ if border_type == 'median': destination_border = destination_lane['median'] origin_border = origin_lane['median'] else: destination_border = destination_lane[border_type + '_border'] origin_border = origin_lane[border_type + '_border'] cut_size = origin_lane['crosswalk_width']*5.0 shorten_origin_border = shorten_border_for_crosswalk(origin_border, origin_lane['name'], all_lanes, destination='to_intersection', crosswalk_width=cut_size ) shorten_origin_border = extend_origin_border(shorten_origin_border, length=cut_size, relative=True) shorten_origin_border = shorten_border_for_crosswalk(shorten_origin_border, origin_lane['name'], all_lanes, destination='to_intersection', crosswalk_width=0.0 ) shorten_destination_border = shorten_border_for_crosswalk(destination_border, destination_lane['name'], all_lanes, destination='from_intersection', crosswalk_width=cut_size ) shorten_destination_border = extend_destination_border(shorten_destination_border, length=cut_size, relative=True) shorten_destination_border = shorten_border_for_crosswalk(shorten_destination_border, destination_lane['name'], all_lanes, destination='from_intersection', crosswalk_width=0.0 ) turn_arc = construct_u_turn_arc(shorten_origin_border, shorten_destination_border) if turn_arc is None: return None return shorten_origin_border + turn_arc[1:]
def get_lanes_close_to_the_intersection(x_data, crosswalk_width=1.82): """ Get a subset of lanes that are adjacent to the intersection center for construction of crosswalks. Lanes that ends at a distance to the center are excluded. :param lanes: :param crosswalk_width: :return: list of lane dictionaries """ close_lanes = [] for lane_data in x_data['merged_lanes']: if [n for n in lane_data['nodes'] if n in x_data['x_nodes']]: close_lanes.append(lane_data) continue dist = get_distance_from_point_to_line( (x_data['center_x'], x_data['center_y']), lane_data['median']) logger.debug("Distance from center to %d %s is %r" % (lane_data['id'], lane_data['name'], dist)) if get_distance_from_point_to_line( (x_data['center_x'], x_data['center_y']), lane_data['median']) < 4 * crosswalk_width: close_lanes.append(lane_data) continue median = shorten_border_for_crosswalk( lane_data['median'], lane_data['name'], x_data['merged_lanes'], crosswalk_width=5 * crosswalk_width, destination=lane_data['direction']) if get_border_length(median) < lane_data['length']: close_lanes.append(lane_data) return close_lanes
def get_simulated_crosswalk(street_data, streets, width=1.8): """ Construct a simulated crosswalk :param street_data: street dictionary :param streets: list of dictionaries :param width: float, crosswalk width in meters :return: crosswalk dictionary """ if is_highway(street_data): return None logger.debug("Simulated crosswalk for %s" % street_data['name']) right_border = shorten_border_for_crosswalk(street_data['right_border'], street_data['name'], streets, crosswalk_width=3, destination='to_intersection', exclude_parallel=True, max_reduction=130.0 ) left_border = shorten_border_for_crosswalk(street_data['left_border'], street_data['name'], streets, crosswalk_width=3, destination='to_intersection', exclude_parallel=True, max_reduction=130.0 ) right_border2 = shorten_border_for_crosswalk(street_data['right_border'], street_data['name'], streets, crosswalk_width=3 + width, destination='to_intersection', exclude_parallel=True, max_reduction=130.0 ) left_border2 = shorten_border_for_crosswalk(street_data['left_border'], street_data['name'], streets, crosswalk_width=3 + width, destination='to_intersection', exclude_parallel=False, max_reduction=130.0 ) vector = [right_border[-1], right_border2[-1]] resized_vector = extend_vector(vector, length=width, backward=False) vector2 = [get_closest_point(p, street_data['left_border']) for p in resized_vector] # logger.debug("Vector %r" % vector) # logger.debug("Resize %r" % resized_vector) # logger.debug("Vecto2 %r" % vector2) r_b = [right_border[-1], left_border[-1]] r_l = [shift_by_bearing_and_distance(r_b[0], width, [right_border[-1], right_border[-2]], bearing_delta=0.0), shift_by_bearing_and_distance(r_b[-1], width, [left_border[-1], left_border[-2]], bearing_delta=0.0)] crosswalk = { 'lane_id': '1C', 'name': street_data['name'], 'simulated': 'yes', # 'right_border': [vector[0], vector2[0]], # 'left_border': [resized_vector[1], vector2[1]], 'right_border': r_b, # [right_border[-1], left_border[-1]], 'left_border': r_l, # [right_border2[-1], left_border2[-1]], 'median': shift_vector([right_border[-1], left_border[-1]], -width / 2.0), 'path_id': 0, 'path': [], 'lane_type': 'crosswalk', 'direction': 'undefined', 'nodes': [], 'nodes_coordinates': [], 'width': width, 'type': 'footway' } bearing = get_compass(crosswalk['right_border'][0], crosswalk['right_border'][-1]) crosswalk['bearing'] = bearing crosswalk['compass'] = get_compass_rhumb(bearing), crosswalk['length'] = get_border_length(crosswalk['median']) if crosswalk['length'] > 50.0: return None if "id" in street_data: crosswalk["street_id"] = street_data["id"] logger.debug( 'Created crosswalk for street %s %s' % (street_data['name'], street_data['compass'])) return crosswalk
def get_u_turn_border(origin_lane, destination_lane, all_lanes, border_type='left', reduction=5.0): """ Construct a border of a u-turn guideway :param origin_lane: dictionary :param destination_lane: dictionary :param all_lanes: list of dictionaries :param border_type: string: either 'left' or 'right' or 'median' :return: list of coordinates """ if border_type == 'median': destination_border = destination_lane['median'] origin_border = origin_lane['median'] else: destination_border = destination_lane[border_type + '_border'] origin_border = origin_lane[border_type + '_border'] cut_size = origin_lane['crosswalk_width'] * 5.0 if can_we_skip_shortening(origin_lane, destination_lane, all_lanes): o_b = reduce_line_by_distance(origin_border, reduction) d_b = reduce_line_by_distance(destination_border, reduction, at_the_end=False) o_b = drop_small_edges(o_b) d_b = drop_small_edges(d_b) turn_arc = construct_u_turn_arc(o_b, d_b) if turn_arc is None: return None return o_b + turn_arc[1:] shorten_origin_border = shorten_border_for_crosswalk( origin_border, origin_lane['name'], all_lanes, destination='to_intersection', crosswalk_width=cut_size) # logger.debug('1st %s, shorten border %r' % (border_type, shorten_origin_border)) shorten_origin_border = extend_origin_border(shorten_origin_border, length=cut_size, relative=True) # logger.debug('2nd %s, shorten border %r' % (border_type, shorten_origin_border)) shorten_origin_border = shorten_border_for_crosswalk( shorten_origin_border, origin_lane['name'], all_lanes, destination='to_intersection', crosswalk_width=0.0, max_reduction=999) # logger.debug('3rd %s, shorten border %r' % (border_type, shorten_origin_border)) shorten_destination_border = shorten_border_for_crosswalk( destination_border, destination_lane['name'], all_lanes, destination='from_intersection', crosswalk_width=cut_size, origin=False) shorten_destination_border = extend_destination_border( shorten_destination_border, length=cut_size, relative=True) shorten_destination_border = shorten_border_for_crosswalk( shorten_destination_border, destination_lane['name'], all_lanes, destination='from_intersection', crosswalk_width=0.0, origin=False, max_reduction=999) turn_arc = construct_u_turn_arc(shorten_origin_border, shorten_destination_border) origin_lane[border_type + "_" + "shorten_origin_border"] = turn_arc destination_lane[border_type + "_" + "shorten_destination_border"] = turn_arc if turn_arc is None: return None return shorten_origin_border + turn_arc[1:]