Ejemplo n.º 1
0
def plot_fit_offsets(hull: shg.Polygon, box_minus: shg.Polygon,
                     box_plus: shg.Polygon, angle: float,
                     model_length_largest: bool, centroid_x: float,
                     centroid_y: float, model_name: str, osm_id: int) -> None:
    pdf_pages = pu.create_pdf_pages('fit_offset_' + str(osm_id))

    my_figure = pu.create_a4_landscape_figure()
    title = 'osm_id={},\n model={},\n angle={},\n length_largest={}'.format(
        osm_id, model_name, angle, model_length_largest)
    my_figure.suptitle(title)

    ax = my_figure.add_subplot(111)

    patch = PolygonPatch(hull, facecolor='none', edgecolor="black")
    ax.add_patch(patch)
    patch = PolygonPatch(box_minus, facecolor='none', edgecolor="green")
    ax.add_patch(patch)
    patch = PolygonPatch(box_plus, facecolor='none', edgecolor="red")
    ax.add_patch(patch)
    ax.add_patch(
        pat.Circle((centroid_x, centroid_y),
                   radius=0.4,
                   linewidth=2,
                   color='blue',
                   fill=False))
    bounds = bounds_from_list([box_minus.bounds, box_plus.bounds])
    pu.set_ax_limits_bounds(ax, bounds)

    pdf_pages.savefig(my_figure)

    pdf_pages.close()

    sleep(2)  # to make sure we have not several files in same second
Ejemplo n.º 2
0
def draw_rectify(rectify_buildings: List[bl.RectifyBuilding], max_samples: int,
                 seed_sample: bool) -> None:
    number_of_samples = len(rectify_buildings)
    if number_of_samples > max_samples:
        number_of_samples = max_samples
    if seed_sample:
        random.seed()
    samples_list = random.sample(rectify_buildings, number_of_samples)

    pdf_pages = pu.create_pdf_pages("rectify_buildings")

    for sample in samples_list:
        my_figure = pu.create_a4_landscape_figure()
        my_figure.suptitle(
            "Building with OSM id = %i. \nIf green then node to change;\nif blue then 90 degrees;\
\n else red;\nif filled then corner of a bow; \nif light color then part of multiple buildings.\
\nOriginal boundary is red, new boundary is green." % sample.osm_id)
        ax = my_figure.add_subplot(111)
        original_x_array = np.zeros(len(sample.node_refs) +
                                    1)  # because we need to close the loop
        original_y_array = np.zeros(len(sample.node_refs) + 1)
        updated_x_array = np.zeros(len(sample.node_refs) + 1)
        updated_y_array = np.zeros(len(sample.node_refs) + 1)
        blocked_nodes = list()
        nodes_to_change = list()
        for position in range(len(sample.node_refs) + 1):
            node_position = position
            if position == len(sample.node_refs):
                node_position = 0
            node = sample.node_refs[node_position]
            rectify_node = node.my_node
            original_x_array[position] = rectify_node.original_x
            original_y_array[position] = rectify_node.original_y
            updated_x_array[position] = rectify_node.x
            updated_y_array[position] = rectify_node.y
            if node.is_blocked():
                blocked_nodes.append(node)
            elif node.within_rectify_deviation():
                nodes_to_change.append(node)
        pu.set_ax_limits(ax, min(original_x_array), min(original_y_array),
                         max(original_x_array), max(original_y_array))
        ax.plot(original_x_array,
                original_y_array,
                color='red',
                linewidth=1,
                solid_capstyle='round',
                zorder=2)
        ax.plot(updated_x_array,
                updated_y_array,
                color='green',
                linewidth=1,
                solid_capstyle='round',
                zorder=3)
        _draw_blocked_nodes(blocked_nodes, ax)
        _draw_nodes_to_change(nodes_to_change, ax)
        pdf_pages.savefig(my_figure)

    pdf_pages.close()
    plt.close("all")
Ejemplo n.º 3
0
def plot_blocked_areas_and_stg_entries(blocked_areas: List[shg.Polygon],
                                       static_objects: List[shg.Polygon],
                                       shared_objects: List[shg.Polygon],
                                       before: List[shg.Polygon],
                                       after: List[shg.Polygon],
                                       transform: co.Transformation) -> None:
    pdf_pages = pu.create_pdf_pages('blocked_apt_areas_incl_stg_objects')

    # Blocked areas
    my_figure = pu.create_large_figure()
    my_figure.suptitle(
        'Blocked Areas for airports (magenta) as well as static (green) and shared (cyan) stg entries\
and buildings (yellow)')
    ax = my_figure.add_subplot(111)

    # first blocked areas
    pu.add_list_of_polygons(ax, blocked_areas, 'magenta', 'magenta')
    # then the static stg entries
    pu.add_list_of_polygons(ax, static_objects, 'green', 'green')
    # then the shared stg entries
    pu.add_list_of_polygons(ax, shared_objects, 'cyan', 'cyan')
    # and finally the shared stg entries
    pu.add_list_of_polygons(ax, before, 'yellow', 'yellow')
    pu.set_ax_limits_from_tile(ax, transform)
    pdf_pages.savefig(my_figure)

    my_figure = pu.create_large_figure()
    my_figure.suptitle('Before buildings (red) and after buildings (yellow)')
    ax = my_figure.add_subplot(111)
    pu.add_list_of_polygons(ax, before, 'red', 'red')
    pu.add_list_of_polygons(ax, after, 'yellow', 'yellow')
    pu.set_ax_limits_from_tile(ax, transform)
    pdf_pages.savefig(my_figure)

    my_figure = pu.create_large_figure()
    my_figure.suptitle('Only blocked areas')
    ax = my_figure.add_subplot(111)
    pu.add_list_of_polygons(ax, blocked_areas, 'magenta', 'magenta')
    pu.add_list_of_polygons(ax, static_objects, 'green', 'green')
    pu.add_list_of_polygons(ax, shared_objects, 'cyan', 'cyan')
    pu.set_ax_limits_from_tile(ax, transform)
    pdf_pages.savefig(my_figure)

    pdf_pages.close()
    plt.close("all")
Ejemplo n.º 4
0
def draw_buildings(building_zones, bounds) -> None:
    pdf_pages = pu.create_pdf_pages("would-be-buildings")

    # Generated buildings
    my_figure = pu.create_a3_landscape_figure()
    my_figure.suptitle(
        "Generated buildings (yellow) and other blocked areas \n[yellow=generated building"
        +
        ", blue=OSM building, dark green=open space, orange=other blocked area]"
    )
    ax = my_figure.add_subplot(111)
    _draw_background_zones(building_zones, ax)
    _draw_blocked_areas(building_zones, ax)
    for building_zone in building_zones:
        _draw_buildings(building_zone.osm_buildings, ax)
    _set_ax_limits_from_bounds(ax, bounds)
    pdf_pages.savefig(my_figure)

    pdf_pages.close()
    plt.close("all")
Ejemplo n.º 5
0
def plot_blocked_areas_roads(blocked_areas: List[shg.Polygon],
                             ways: List[shg.LineString],
                             transform: co.Transformation) -> None:
    pdf_pages = pu.create_pdf_pages('blocked_areas_roads')

    # Generated buildings
    my_figure = pu.create_a3_landscape_figure()
    my_figure.suptitle("Blocked Areas")
    ax = my_figure.add_subplot(111)

    # first blocked areas
    pu.add_list_of_polygons(ax, blocked_areas, 'magenta', 'black')

    # then the lines
    for line in ways:
        pu.plot_line(ax, line, 'green', 1)

    pu.set_ax_limits_from_tile(ax, transform)
    pdf_pages.savefig(my_figure)

    pdf_pages.close()
    plt.close("all")
Ejemplo n.º 6
0
def draw_zones(buildings: List[bl.Building],
               building_zones: List[m.BuildingZone],
               btg_building_zones: List[m.BTGBuildingZone],
               btg_water_areas: List[Polygon], lit_areas: List[Polygon],
               bounds: m.Bounds) -> None:
    pdf_pages = pu.create_pdf_pages("landuse")

    # OSM building zones original
    my_figure = pu.create_a3_landscape_figure()
    my_figure.suptitle(
        "Original OpenStreetMap building zones \n[blue=commercial, green=industrial, dark orange=retail\
, magenta=residential, brown=farmyard, purple=aerodrome, red=error]")
    ax = my_figure.add_subplot(111)
    _draw_osm_zones(building_zones, ax)
    _set_ax_limits_from_bounds(ax, bounds)
    pdf_pages.savefig(my_figure)

    # Only water from BTG
    my_figure = pu.create_a3_landscape_figure()
    my_figure.suptitle("Water from FlightGear BTG files")
    ax = my_figure.add_subplot(111)
    _draw_btg_water_areas(btg_water_areas, ax)
    _set_ax_limits_from_bounds(ax, bounds)
    pdf_pages.savefig(my_figure)

    # External land use from BTG
    if btg_building_zones:
        my_figure = pu.create_a3_landscape_figure()
        my_figure.suptitle(
            "Land-use types from FlightGear BTG files \n[magenta=builtupcover and urban, \
gold=town and suburban, yellow=construction and industrial and port, light blue=water]"
        )
        ax = my_figure.add_subplot(111)
        ax.grid(True, linewidth=1, linestyle="--", color="silver")
        _draw_btg_water_areas(btg_water_areas, ax)
        _draw_btg_building_zones(btg_building_zones, ax)
        _draw_buildings(buildings, ax)
        _set_ax_limits_from_bounds(ax, bounds)
        pdf_pages.savefig(my_figure)

    # All land-use
    my_figure = pu.create_a3_landscape_figure()
    my_figure.suptitle(
        "Original OpenStreetMap and generated building zones \n[blue=commercial, green=industrial\
, dark orange=retail, magenta=residential, brown=farmyard, purple=aerodrome, red=error;\n \
lighter variants=generated from buildings;\
\ncyan=commercial and industrial, gold=continuous urban, yellow=discontinuous urban]"
    )
    ax = my_figure.add_subplot(111)
    _draw_btg_water_areas(btg_water_areas, ax)
    _draw_osm_zones(building_zones, ax)
    _draw_generated_zones(building_zones, ax)
    _draw_buildings(buildings, ax)
    _set_ax_limits_from_bounds(ax, bounds)
    pdf_pages.savefig(my_figure)

    # Lit areas
    my_figure = pu.create_a3_landscape_figure()
    my_figure.suptitle("Lit areas from building zones")
    ax = my_figure.add_subplot(111)
    ax.grid(True, linewidth=1, linestyle="--", color="silver")
    _draw_btg_water_areas(btg_water_areas, ax)
    _draw_lit_areas(lit_areas, ax)
    _set_ax_limits_from_bounds(ax, bounds)
    pdf_pages.savefig(my_figure)

    # Settlement type
    my_figure = pu.create_a3_landscape_figure()
    my_figure.suptitle(
        "Built-up areas by settlement type \n[blue=centre (city), green=block, magenta=dense, \n \
    yellow=periphery, grey=rural, brown=farmyard]. If hatched, then type upgraded or downgraded for sanity."
    )
    ax = my_figure.add_subplot(111)
    _draw_btg_water_areas(btg_water_areas, ax)
    _draw_settlement_zones(building_zones, ax)
    _set_ax_limits_from_bounds(ax, bounds)
    pdf_pages.savefig(my_figure)

    # Density of zones
    my_figure = pu.create_a3_landscape_figure()
    my_figure.suptitle(
        "Density (ratio of building floor plan area to total area).\n \
    Light grey up to .05, Yellow up to .1, orange up to 0.15, red up to .2,\n \
    dark red up to .25, lime up to .3, green up to .4, dark green up to .45, black afterwards"
    )
    ax = my_figure.add_subplot(111)
    _draw_btg_water_areas(btg_water_areas, ax)
    _draw_zones_density(building_zones, ax)
    _set_ax_limits_from_bounds(ax, bounds)
    pdf_pages.savefig(my_figure)

    # City blocks
    my_figure = pu.create_a3_landscape_figure()
    my_figure.suptitle("City blocks random pattern")
    ax = my_figure.add_subplot(111)
    ax.grid(True, linewidth=1, linestyle="--", color="silver")
    _draw_city_blocks(building_zones, ax)
    _set_ax_limits_from_bounds(ax, bounds)
    pdf_pages.savefig(my_figure)

    pdf_pages.close()
    plt.close("all")