Beispiel #1
0
def process_query_results(query_results_dict, map_item):

    processed_query_results_dict = {}
    # we find the min and max passengers for the whole year
    min_passenger = 999999999
    max_passenger = 0
    for query_date in query_results_dict:
        temp_min, temp_max = Utils.compute_min_max_passengers(query_results_dict[query_date], 2)
        if temp_min < min_passenger:
            min_passenger = temp_min
        if temp_max > max_passenger:
            max_passenger = temp_max

    # we transform the query_results_dict to use instances of the PointOnMap class
    for query_date in query_results_dict:
        query_result = query_results_dict[query_date]
        processed_query_results_dict[query_date] = []
        for itinerary in query_result:
            processed_itinerary = []
            zone_id_origin = Utils.convert_id(itinerary[0])
            zone_id_destination = Utils.convert_id(itinerary[1])
            if zone_id_origin == zone_id_destination:
                color = (141, 91, 67)
            else:
                color = (135, 162, 34)

            weight = compute_weight(map_item[0], itinerary[2], max_passenger)

            shape_origin = map_item[1].shape_dict[zone_id_origin]
            coords = shape_origin.center
            point_to_render = classfile.PointOnMap(coords, weight, color)
            processed_itinerary.append(point_to_render)

            shape_dest = map_item[1].shape_dict[zone_id_destination]
            target_coords = shape_dest.center
            processed_itinerary.append(target_coords)

            processed_itinerary.append(weight)
            processed_query_results_dict[query_date].append(processed_itinerary)

    return processed_query_results_dict, min_passenger, max_passenger
Beispiel #2
0
def render_single_map(flow_dict, flow_dir, base_map, file_name, zone_shape):

    map_rendered = base_map.map_file.copy()
    zone_name = find_names(zone_shape, base_map)
    zone_id = Utils.convert_id(zone_shape.shape_id, inverse=True)
    map_title = '{}_{}_{}_{}_{}'.format(file_name[0], zone_id, zone_name,
                                        flow_dir, file_name[1])
    trips_list = flow_dict[zone_shape]
    min_passenger, max_passenger = Utils.compute_min_max_passengers(
        trips_list, 1)

    colors = []
    for linked_zone in trips_list:
        shape_to_color = linked_zone[0]
        if shape_to_color.shape_id != zone_shape.shape_id:
            weight = linked_zone[1]
            render_color = compute_color(weight, min_passenger, max_passenger)
            shape_to_color.color_fill = render_color
            if render_color not in colors:
                colors.append(render_color)
            shape_to_color.fill_in_shape(map_rendered)
            # we draw again the boundaries of the shape after filling it in
            pts = np.array(shape_to_color.points, np.int32)
            cv2.polylines(map_rendered, [pts], True, (255, 255, 255), 1,
                          cv2.LINE_AA)

    # outline the focused shape
    zone_shape.color_line = [95, 240, 255]
    zone_shape.line_thick = 3
    pts = np.array(zone_shape.points, np.int32)
    cv2.polylines(map_rendered, [pts], True, zone_shape.color_line,
                  zone_shape.line_thick, cv2.LINE_AA)
    # display the legend
    display_specific_text(map_rendered, zone_id, zone_name, flow_dir,
                          min_passenger, max_passenger, colors)

    # save the image
    cv2.imwrite(('{}.png').format(map_title), map_rendered)