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

update: minor progress, part of map

parent 59a0e44e
No related branches found
No related tags found
1 merge request!6Clhp map
No preview for this file type
......@@ -30,8 +30,8 @@ def get_relation(self, body_of_water: str):
# Divide the length and with of polygon into a grid
grid_lines = create_grid_coords(polygon, cell_size=0.1)
hrz_lines = grid_lines[0] # Horizontal coordinates
vrt_lines = grid_lines[1] # Vertical coordinates
hrz_lines = [60.7451] # Horizontal coordinates
vrt_lines = [10.9600] # Vertical coordinates
# Cut polygon into horizontal sections
for hrz_line in hrz_lines:
......@@ -50,7 +50,7 @@ def get_relation(self, body_of_water: str):
if not cut_poly_2[0]:
continue
divided_map.extend(cut_poly_2[0]) # Append part to final list of shapes
divided_map.append(cut_poly_2[0]) # Append part to final list of shapes
# Set polygon_part to the remaining, un-split, horizontal section for next iteration
polygon_part = cut_poly_2[1]
......@@ -92,26 +92,31 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool):
for point in exterior_coords:
point = Point(point) # Convert coordinates to Shapely Point object
if horizontal: # Horizontal split
if point.y < divisor:
if point.y > divisor:
split_shape.append(point)
else:
remaining_shape.append(point)
else: # Vertical split
if point.x < divisor:
if point.x > divisor:
split_shape.append(point)
else:
remaining_shape.append(point)
# Check if polygons have enough coordinates
if len(split_shape) < 3 or len(remaining_shape) < 3:
print("Not enough coordinates to create valid polygons")
return None, None
if len(split_shape) < 3:
print("Not enough coordinates to create valid polygons: Split shape")
split_shape = None
else:
split_shape.append(split_shape[0]) # NB: may not be necessary?
# Append the first coordinate of the shapes to create closed loop
split_shape.append(split_shape[0]) # NB: may not be necessary?
remaining_shape.append(remaining_shape[0])
if len(remaining_shape) < 3:
print("Not enough coordinates to create valid polygons: Remaining shape")
remaining_shape = None
else:
remaining_shape.append(remaining_shape[0])
return Polygon(split_shape), Polygon(remaining_shape) # Return split polygons as Shapely Polygon objects
# Return split polygons as Shapely Polygon objects
return Polygon(split_shape), Polygon(remaining_shape)
# Generate grid of equally spaced x and y coordinates where the grid size is determined by cell_size
......@@ -123,5 +128,6 @@ def create_grid_coords(polygon: Polygon, cell_size: float):
if len(x_coords) == 0 or len(y_coords) == 0:
raise ValueError("No grid points generated")
# Return tuple of list of x coordinates and list of y coordinates
return x_coords, y_coords
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