Ejemplo n.º 1
0
def process_query_results(query_results, base_map):

    in_shape_ids = []
    incoming_flow = {}
    out_shape_ids = []
    outgoing_flow = {}

    for itinerary in query_results:
        origin_id = Utils.convert_id(itinerary[0])
        destination_id = Utils.convert_id(itinerary[1])
        weight = itinerary[2]
        origin_ids = []
        destination_ids = []
        # we look only at shapes that are to be rendered
        if origin_id in base_map.shape_dict or destination_id in base_map.shape_dict:
            shape_origin = base_map.shape_dict[origin_id]
            origin_ids.append(origin_id)
            shape_destination = base_map.shape_dict[destination_id]
            destination_ids.append(destination_id)

        # We build a dictionary of outgoing traffic
        for origin_id in origin_ids:
            if origin_id not in out_shape_ids:
                out_shape_ids.append(origin_id)
                outgoing_flow[shape_origin] = []
            outgoing_flow[shape_origin].append((shape_destination, weight))
        # We build a dictionary of incoming traffic
        for destination_id in destination_ids:
            if destination_id not in in_shape_ids:
                in_shape_ids.append(destination_id)
                incoming_flow[shape_destination] = []
            incoming_flow[shape_destination].append((shape_origin, weight))

    return outgoing_flow, incoming_flow
Ejemplo n.º 2
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
Ejemplo n.º 3
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)