diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index 140394c18ade684876d995f2db2b1352085f9609..744144e33606421cf5d36ed1c24d8c6e2ddab9df 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 c43bb7001c18d14cb792c9b0ff44871699593192..52b037aad68814c42094d7fadeb18fccd9c43f2b 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -26,12 +26,15 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water if not polygons: raise ValueError("Failed to convert to polygons") - divided_map = [] + divided_map = [] # List to store map shapes while splitting + + # NB: test polygon, remove after testing + polygons = [circle_polygon()] # Divide all polygons into sections for polygon in polygons: - cell_size = 0.1 + cell_size = 0.4 # Divide the length and with of polygon into a grid of equally sized parts grid_lines = create_grid_coords(polygon, cell_size) @@ -50,18 +53,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water if not horizontal_section or not divided_poly[0]: continue - # Cut each horizontal section into vertical sections, right to left - for vrt_line in vrt_lines: - 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_by_points(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] + divided_map.append(horizontal_section) divided_map.append(polygon) @@ -115,7 +107,9 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float): remaining_shape.append(point) # Add points to the newly created edges of split_shape and remaining_shape - split_shape, remaining_shape = populate_new_edge(split_shape, remaining_shape, cell_size, divisor) + populate_new_edge(split_shape, remaining_shape, cell_size, divisor) + #split_shape = shape_w_edges[0] + #remaining_shape = shape_w_edges[1] else: # Vertical split for point in exterior_coords: @@ -154,11 +148,10 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f right_corner = split_shape[-1] left_corner = split_shape[0] - print("right_corner: ", right_corner, " left_corner: ", left_corner, " cell_size: ", cell_size) + print("right_corner: ", right_corner, " left_corner: ", left_corner, " left == right?: ", left_corner == right_corner) while starting_point < left_corner.x: # Increment starting point until it is withing the polygons bounds starting_point += cell_size - # 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) @@ -177,19 +170,28 @@ def create_grid_coords(polygon: Polygon, cell_size: float): # Define boundaries of grid min_x, min_y, max_x, max_y = polygon.bounds - global polygon_min_x # Set value of global variable - polygon_min_x = min_x - # Divide grid into sections of size *cell_size - x_coords = np.arange(min_x, max_x, cell_size) - y_coords = np.arange(min_y, max_y, cell_size) + x_step = max((max_x - min_x) / 10, cell_size) + y_step = max((max_y - min_y) / 10, cell_size) + + x_coords = np.arange(min_x, max_x + x_step, x_step) + y_coords = np.arange(min_y, max_y + y_step, y_step) + + return x_coords, y_coords + - # Round coordinates to 4 decimals - x_coords_rounded = np.around(x_coords, decimals=4) - y_coords_rounded = np.around(y_coords, decimals=4) +# NB: only for testing +def circle_polygon(): + circle_points = [] + num_points = 80 + center_x, center_y = 0.0, 0.0 + radius = 6 - if len(x_coords_rounded) == 0 or len(y_coords_rounded) == 0: - raise ValueError("No grid points generated") + for i in range(num_points): + angle = 2 * np.pi * i / num_points + x = center_x + radius * np.cos(angle) + y = center_y + radius * np.sin(angle) + circle_points.append((x, y)) + circle_points.append(circle_points[0]) # Close the circle - # Return tuple of list of x coordinates and list of y coordinates - return x_coords_rounded, y_coords_rounded + return Polygon(circle_points) \ No newline at end of file