Exemplo n.º 1
0
def get_mapdata(map_dir):
    print 'Please wait for loading map data...'
    map_data_path = os.path.join(map_dir, 'base_map.bin')
    print "file: ", map_data_path
    f_handle = open(map_data_path)
    base_map = map_pb2.Map()
    base_map.ParseFromString(f_handle.read())
    f_handle.close()
    print 'Done'
    return base_map
Exemplo n.º 2
0
def run(gmap_key, map_file, utm_zone):
    """
    read and process map file
    """
    map_pb = map_pb2.Map()
    proto_utils.get_pb_from_file(map_file, map_pb)

    left_boundaries = []
    right_boundaries = []
    center_lat = None
    center_lon = None
    for lane in map_pb.lane:
        for curve in lane.left_boundary.curve.segment:
            if curve.HasField('line_segment'):
                left_boundary = []
                for p in curve.line_segment.point:
                    point = {}
                    lat, lng = utm2latlon(p.x, p.y, utm_zone)
                    if center_lat is None:
                        center_lat = lat
                    if center_lon is None:
                        center_lon = lng
                    point['lat'] = lat
                    point['lng'] = lng
                    left_boundary.append(point)
                left_boundaries.append(left_boundary)
        for curve in lane.right_boundary.curve.segment:
            if curve.HasField('line_segment'):
                right_boundary = []
                for p in curve.line_segment.point:
                    point = {}
                    lat, lng = utm2latlon(p.x, p.y, utm_zone)
                    point['lat'] = lat
                    point['lng'] = lng
                    right_boundary.append(point)
                right_boundaries.append(right_boundary)

    html = generate(gmap_key, left_boundaries, right_boundaries, center_lat,
                    center_lon)

    with open('gmap.html', 'w') as file:
        file.write(html)
Exemplo n.º 3
0
Arquivo: util.py Projeto: zk20/apollo
def get_mapdata(map_dir):
    print('Please wait for loading map data...')
    map_data_path = os.path.join(map_dir, 'base_map.bin')
    print('File: %s' % map_data_path)
    return proto_utils.get_pb_from_bin_file(map_data_path, map_pb2.Map())
        # Convert lane points from pixel coordinates to Carla coordinates
        for lntype in contours['lanes']:
            for i in range(len(contours['lanes'][lntype])):
                contours['lanes'][lntype][i] = list(
                    map(pixel_to_coord, contours['lanes'][lntype][i]))

        # Convert junction polygons from pixel coordinates to Carla coordinates
        for i in range(len(junctions)):
            junctions[i] = list(map(pixel_to_coord, junctions[i]))

        # Save raw data
        pkl.dump((contours, junctions), open(RAW_DATA_FILE, 'wb'))

    # Create map object
    map = map_pb2.Map()
    road_dict = {}
    lane_dict = {}
    junction_dict = {}
    overlap_dict = {}
    ID = 1
    all_lanes = contours['lanes']
    # Create road and lane objects
    for lntype in all_lanes:
        for lane in all_lanes[lntype]:
            # Create basic road object
            road_dict[str(ID)] = Road(str(ID), map)
            # Create basic lane object
            lane_ID = str(ID) + '_1_-1'
            new_lane = Lane(lane_ID, map)
            LANE_TURN = {
Exemplo n.º 5
0
 def __init__(self):
     self.map_pb = map_pb2.Map()
     self.colors = []
     self.init_colors()
Exemplo n.º 6
0
 def __init__(self):
   self.map_pb = map_pb2.Map()
Exemplo n.º 7
0
def get_points(input):
    folder = "/apollo/modules/map/data/" + input[0].lower()
    map_pb = map_pb2.Map()
    get_pb_from_text_file(folder + '/sim_map.txt', map_pb)
    lanes = input[1].copy()
    for lane_pb in map_pb.lane:
        if lane_pb.id.id in lanes.keys():
            lanes[lane_pb.id.id] = lane_pb

    if len(lanes) == 1:
        lane = lanes[list(
            lanes.keys())[0]].central_curve.segment[0].line_segment
        min_distance_start = sys.float_info.max
        min_distance_end = sys.float_info.max
        points = []
        for point in lane.point:
            cur_distance_start = distance(float(point.x), float(point.y),
                                          input[2][0][0], input[2][0][1])
            cur_distance_end = distance(float(point.x), float(point.y),
                                        input[2][1][0], input[2][1][1])
            if cur_distance_start < min_distance_start:
                points = []
                min_distance_start = cur_distance_start

            if cur_distance_end < min_distance_end:
                min_distance_end = cur_distance_end
            elif cur_distance_end > min_distance_end:
                break

            points.append([point.x, point.y])

        return points

    start_lane = lanes[list(
        lanes.keys())[0]].central_curve.segment[0].line_segment
    min_distance = sys.float_info.max
    start_points = []
    for point in start_lane.point:
        cur_distance = distance(float(point.x), float(point.y), input[2][0][0],
                                input[2][0][1])
        if cur_distance < min_distance:
            start_points = []
            min_distance = cur_distance
        start_points.append([point.x, point.y])

    middle_points = []
    for key in list(lanes.keys())[1:-1]:
        lane = lanes[key]
        for point in lane.central_curve.segment[0].line_segment.point:
            middle_points.append([point.x, point.y])

    end_lane = lanes[list(
        lanes.keys())[-1]].central_curve.segment[0].line_segment
    point = end_lane.point[0]
    min_distance = sys.float_info.max
    end_points = []
    for point in end_lane.point:
        cur_distance = distance(float(point.x), float(point.y), input[2][1][0],
                                input[2][1][1])
        if cur_distance < min_distance:
            end_points.append([point.x, point.y])
            min_distance = cur_distance
        elif cur_distance > min_distance:
            break

    return start_points + middle_points + end_points


#print(get_points(input1))
Exemplo n.º 8
0
def load_map_data(map_file):
    map_pb = map_pb2.Map()
    proto_utils.get_pb_from_file(map_file, map_pb)
    return map_pb
Exemplo n.º 9
0
    def __init__(self, input_file_name, output_file_name=None) -> None:
        self.xodr_map = Map()
        self.xodr_map.load(input_file_name)

        self.pb_map = map_pb2.Map()
        self.output_file_name = output_file_name