Commit b49f9053 authored by Rick Gruber-Riemer's avatar Rick Gruber-Riemer

RGet simplify balconies done before roof hints

parent 7842b035
......@@ -349,23 +349,25 @@ class Building(object):
self.outer_nodes_closest = [y for (y, x) in yx]
self._set_polygon(self.polygon.exterior, self.inner_rings_list)
def simplify(self) -> int:
def simplify(self, nodes_dict: Dict[int, op.Node], coords_transform: co.Transformation) -> int:
"""Simplifies the geometry, but only if no inners."""
if self.has_inner:
return 0
original_number = len(self.polygon.exterior.coords)
count_simplified = 0
while True:
simplified = utilities.simplify_balconies(self.polygon, parameters.BUILDING_SIMPLIFY_TOLERANCE_LINE,
parameters.BUILDING_SIMPLIFY_TOLERANCE_AWAY, self.refs_shared)
if simplified is None:
to_remove = utilities.simplify_balconies(self.polygon, parameters.BUILDING_SIMPLIFY_TOLERANCE_LINE,
parameters.BUILDING_SIMPLIFY_TOLERANCE_AWAY, self.refs_shared)
if len(to_remove) == 0:
break
else:
self.polygon = simplified
simplified_number = len(self.polygon.exterior.coords)
difference = original_number - simplified_number
if difference > 0:
self.geometry = self.polygon # can do this because self.has_inner is False
return difference
count_simplified += 1
new_refs = list()
for i in range(0, len(self.refs)):
if i not in to_remove:
new_refs.append(self.refs[i])
self.refs = new_refs
self.update_geometry_from_refs(nodes_dict, coords_transform)
return count_simplified
def _set_polygon(self, outer: shg.LinearRing, inner: List[shg.LinearRing] = None) -> None:
if inner is None:
......@@ -1561,8 +1563,6 @@ def analyse(buildings: List[Building], fg_elev: utilities.FGElev, stg_manager: s
if _analyse_worship_building(b, building_parent, stg_manager, fg_elev, coords_transform):
continue
if building_parent is None: # do not simplify if in parent/child relationship
stats.nodes_simplified += b.simplify()
try:
b.roll_inner_nodes()
except Exception as reason:
......
......@@ -894,10 +894,17 @@ def process(transformer: Transformation, airports: List[aptdat_io.Airport]) -> T
# run a neighbour analysis -> building.refs_shared
_relate_neighbours(osm_buildings)
last_time = time_logging('Time used in seconds for relating neighbours', last_time)
# simplify the geometry
count_simplified = 0
for building in osm_buildings:
if not building.has_parent: # do not simplify if in parent/child relationship
count_simplified += building.simplify(building_nodes_dict, transformer)
logging.info('Made %i simplifications in total (there can be more than 1 simplification in a building',
count_simplified)
# now we can calculate the roof ridge orientation
for building in osm_buildings:
building.calc_roof_hints(building_nodes_dict, transformer)
last_time = time_logging('Time used in seconds for calculating roof hints', last_time)
last_time = time_logging('Time used in seconds for simplifying and calculating roof hints', last_time)
# FIXME: simplify stuff
# update the geometry a final time based on node references before we loose it
for building in osm_buildings:
......
......@@ -695,7 +695,7 @@ def _safe_index(index: int, number_of_elements: int) -> int:
def simplify_balconies(original: shg.Polygon, distance_tolerance_line: float,
distance_tolerance_away: float, refs_shared: Dict[int, Set[int]]) -> Optional[shg.Polygon]:
distance_tolerance_away: float, refs_shared: Dict[int, Set[int]]) -> Set[int]:
"""Removes edges from polygons, which look like balconies on a building.
Removes always 4 points at a time.
......@@ -754,16 +754,7 @@ def simplify_balconies(original: shg.Polygon, distance_tolerance_line: float,
refs_shared[key] = new_pos_set
break # do not continue the while loop once we have found one balcony to remove
counter += 1
if len(to_remove_points) == 0:
return None
else:
ny_coords = list()
for i in range(len(my_coords)):
if i not in to_remove_points:
ny_coords.append(my_coords[i])
reduced_poly = shg.Polygon(shg.LinearRing(ny_coords))
return reduced_poly
return to_remove_points
def merge_buffers(original_list: List[Polygon]) -> List[Polygon]:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment