diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index 76c8ff54db3931e76b092b850b48ecad05d4aa01..0921934ff5aa4d9b7fbf3b1355ce5214446579e6 100644 Binary files a/server/map/__pycache__/get_relation.cpython-311.pyc and b/server/map/__pycache__/get_relation.cpython-311.pyc differ diff --git a/server/map/get_relation.py b/server/map/get_relation.py index 15d0590ec75cb8f1268d4316be59c42b1d1a8a88..d792f787d2c7ca68da3c5443a180994ffca75ce7 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -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