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

update: add break from splitting horizontal sections

parent 1aec7901
No related branches found
No related tags found
1 merge request!6Clhp map
No preview for this file type
......@@ -27,11 +27,12 @@ def get_relation(self, body_of_water: str):
# Divide all polygons into sections
for polygon in polygons:
# Divide the length and with of polygon into a grid
# Divide the length and with of polygon into a grid of equally sized parts
grid_lines = create_grid_coords(polygon, cell_size=0.1)
hrz_lines = grid_lines[1] # Horizontal coordinates
vrt_lines = grid_lines[0] # Vertical coordinates
vrt_lines = grid_lines[0] # Vertical grid coordinates
hrz_lines = grid_lines[1] # Horizontal grid coordinates
for line in vrt_lines:
print("Line: ", line)
......@@ -39,22 +40,26 @@ def get_relation(self, body_of_water: str):
for hrz_line in hrz_lines:
# Split shape into upper and lower section as hrz_line as divider
cut_poly_1 = cut_polygon_in_two(polygon, hrz_line, True)
polygon_part = cut_poly_1[0] # Save upper horizontal section
divided_poly = cut_polygon_in_two(polygon, hrz_line, True)
horizontal_section = divided_poly[0] # Save upper horizontal section
if not polygon_part or not cut_poly_1[0]:
if not horizontal_section or not divided_poly[0]:
continue
# Cut each horizontal section into vertical sections, right to left
# Cut each horizontal section into vertical sections, right to left
for vrt_line in vrt_lines:
cut_poly_2 = cut_polygon_in_two(polygon_part, vrt_line, False)
if len(horizontal_section.exterior.coords) < 3:
break # Break from loop im remaining section has no coordinates
# Split the horizontal section into two vertical parts
vertical_parts = cut_polygon_in_two(horizontal_section, vrt_line, False)
divided_map.append(cut_poly_2[0]) # Append part to final list of shapes
divided_map.append(vertical_parts[0]) # Append split vertical sections to final list of shapes
# Set polygon_part to the remaining, un-split, horizontal section for next iteration
polygon_part = cut_poly_2[1]
# Set horizontal_section to the remaining, un-split, horizontal section for next iteration
horizontal_section = vertical_parts[1]
polygon = cut_poly_1[1] # Set polygon to the remaining, un-split shape for next iteration
polygon = divided_poly[1] # Set polygon to the remaining, un-split shape for next iteration
divided_map.append(polygon)
......@@ -72,7 +77,7 @@ def get_relation(self, body_of_water: str):
x, y = polygon.exterior.xy
ax.plot(x, y, color='blue', alpha=0.5)
ax.fill(x, y, color=random_color, alpha=0.5)
ax.fill(x, y, color=random_color, alpha=1)
plt.show()
......
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