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

update: attempt to add points to cut dedges

parent 8e591cfd
No related branches found
No related tags found
1 merge request!6Clhp map
No preview for this file type
......@@ -27,22 +27,22 @@ def get_relation(self, body_of_water: str):
# Divide all polygons into sections
for polygon in polygons:
cell_size = 0.1
# Divide the length and with of polygon into a grid of equally sized parts
grid_lines = create_grid_coords(polygon, cell_size=0.1)
grid_lines = create_grid_coords(polygon, cell_size)
vrt_lines = grid_lines[0] # Vertical grid coordinates
hrz_lines = grid_lines[1] # Horizontal grid coordinates
for line in vrt_lines:
print("Line: ", line)
# Cut polygon into horizontal sections, bottom to top
for hrz_line in hrz_lines:
# Split shape into upper and lower section as hrz_line as divider
divided_poly = cut_polygon_in_two(polygon, hrz_line, True)
divided_poly = cut_polygon_in_two(polygon, hrz_line, cell_size)
horizontal_section = divided_poly[0] # Save upper horizontal section
polygon = divided_poly[1] # Set polygon to the remaining, un-split shape for next iteration
if not horizontal_section or not divided_poly[0]:
continue
......@@ -52,15 +52,13 @@ def get_relation(self, body_of_water: str):
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)
vertical_parts = cut_polygon_in_two(horizontal_section, vrt_line, -0.1)
divided_map.append(vertical_parts[0]) # Append split vertical sections to final list of shapes
# Set horizontal_section to the remaining, un-split, horizontal section for next iteration
horizontal_section = vertical_parts[1]
polygon = divided_poly[1] # Set polygon to the remaining, un-split shape for next iteration
divided_map.append(polygon)
break
......@@ -95,7 +93,7 @@ def get_relation(self, body_of_water: str):
# Takes a polygon and divides its coordinates into two shapes, where divisor is a
# coordinate that defines the point of division
def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool):
def cut_polygon_in_two(polygon: Polygon, divisor: float, cell_size: float):
# Extract polygon exterior coordinates
exterior_coords = list(polygon.exterior.coords)
......@@ -104,14 +102,31 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool):
remaining_shape = []
# Loop through points and check which side of the division line they are
for point in exterior_coords:
point = Point(point) # Convert coordinates to Shapely Point object
if horizontal: # Horizontal split
if cell_size > 0: # Horizontal split
for point in exterior_coords:
point = Point(point) # Convert coordinates to Shapely Point object
if point.y < divisor:
split_shape.append(point)
else:
remaining_shape.append(point)
else: # Vertical split
if len(split_shape) > 2:
# Get last point added to
last_point = split_shape[len(split_shape)-1]
# Get length of the newly created edge
new_edge_len = last_point.x - split_shape[0].x - 0.0001
print("new_edge_len: ", new_edge_len, " cell_size: ", cell_size)
# Add points along the new edge to allow horizontal sections to be split into vertical ones
while new_edge_len > cell_size:
print("Hit")
split_shape.append((new_edge_len-cell_size, last_point.y))
remaining_shape.append((new_edge_len-cell_size, last_point.y))
new_edge_len -= cell_size
else: # Vertical split
for point in exterior_coords:
point = Point(point) # Convert coordinates to Shapely Point object
if point.x < divisor:
split_shape.append(point)
else:
......
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