Skip to content
Snippets Groups Projects
Commit adb005ac authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

update: horizontal sections, no spacing, wrong verticals

parent 3aeee368
No related branches found
No related tags found
1 merge request!6Clhp map
No preview for this file type
...@@ -44,7 +44,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water ...@@ -44,7 +44,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water
break # Break from loop im remaining section has no coordinates break # Break from loop im remaining section has no coordinates
# Split the horizontal section into two vertical parts # Split the horizontal section into two vertical parts
vertical_parts = cut_polygon_by_points(horizontal_section, vrt_line, -0.1) vertical_parts = cut_polygon_by_points(horizontal_section, vrt_line, cell_size)
divided_map.append(vertical_parts[0]) # Append split vertical sections to final list of shapes divided_map.append(vertical_parts[0]) # Append split vertical sections to final list of shapes
...@@ -121,6 +121,12 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float): ...@@ -121,6 +121,12 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float):
else: else:
remaining_shape.append((point2.x, point2.y)) remaining_shape.append((point2.x, point2.y))
# Populate newly created edges with points to facilitate vertical cutting
populated_shapes = populate_new_edge(split_shape, remaining_shape, cell_size, divisor)
if populated_shapes is not None:
split_shape = populated_shapes[0]
remaining_shape = populated_shapes[1]
# Ensure that the shapes are closed loops # Ensure that the shapes are closed loops
if len(split_shape) > 0 and split_shape[0] != split_shape[-1]: if len(split_shape) > 0 and split_shape[0] != split_shape[-1]:
split_shape.append(split_shape[0]) split_shape.append(split_shape[0])
...@@ -181,23 +187,23 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f ...@@ -181,23 +187,23 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f
# Find all corners of split shape. Corner = point that intersects divisor # Find all corners of split shape. Corner = point that intersects divisor
for point in split_shape: for point in split_shape:
if divisor_range[0] < point.y < divisor_range[1]: if divisor_range[0] < point[1] < divisor_range[1]:
corners.append(point) corners.append(point)
if not corners or len(corners) < 2: if not corners or len(corners) < 2:
return None return None
# Sort corners in ascending order (left to right) based on x coordinate # Sort corners in ascending order (left to right) based on x coordinate
sorted_corners = sorted(corners, key=lambda p: p.x) sorted_corners = sorted(corners, key=lambda p: p[0])
while starting_point < sorted_corners[0].x: # Increment starting point until it is withing the polygons bounds while starting_point < sorted_corners[0][0]: # Increment starting point until it is withing the polygons bounds
starting_point += cell_size starting_point += cell_size
# if starting_point < left_corner.x: # NB: optimised substitute for previous while loop, requires testing # if starting_point < left_corner.x: # NB: optimised substitute for previous while loop, requires testing
# starting_point += cell_size * math.floor(starting_point - left_corner.x) # starting_point += cell_size * math.floor(starting_point - left_corner.x)
# Insert new points with cell_size spacing while starting_point is within bounds # Insert new points with cell_size spacing while starting_point is within bounds
while starting_point < sorted_corners[-1].x: while starting_point < sorted_corners[-1][0]:
split_shape.insert(0, (starting_point, divisor)) # NB may have to add/subtract small offset of 0.00001 split_shape.insert(0, (starting_point, divisor)) # NB may have to add/subtract small offset of 0.00001
remaining_shape.insert(-1, (starting_point, divisor)) # Prepend new point to shape remaining_shape.insert(-1, (starting_point, divisor)) # Prepend new point to shape
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment