diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index 78b81d93f4fc4f5ee3a9312d3d738fd2d380ea23..96f80953ff49aec41eb8a8c82da8bd1bc35362b4 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 b3a363289816a93defbf52b3b605a5cad41f7c33..40bccf0d40ff030185c86162388bc48d09c2a354 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -19,7 +19,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water # Divide all polygons into sections for polygon in polygons: - cell_size = 0.4 + cell_size = 1.5 # Divide the length and with of polygon into a grid of equally sized parts grid_lines = create_grid_coords(polygon, cell_size) @@ -28,7 +28,6 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water # 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_by_points(polygon, hrz_line, cell_size) horizontal_section = divided_poly[0] # Save upper horizontal section @@ -122,10 +121,13 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float): remaining_shape.append((point2.x, point2.y)) # Populate newly created edges with points to facilitate vertical cutting - populated_shapes = populate_new_edge(split_shape, remaining_shape, cell_size, divisor) - if populated_shapes is not None: - split_shape = populated_shapes[0] - remaining_shape = populated_shapes[1] + populated_split = populate_new_edge(split_shape, cell_size, divisor) + if populated_split is not None: + split_shape = populated_split + + populated_rem = populate_new_edge(remaining_shape, cell_size, divisor) + if populated_rem is not None: + remaining_shape = populated_rem # Ensure that the shapes are closed loops if len(split_shape) > 0 and split_shape[0] != split_shape[-1]: @@ -137,7 +139,6 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float): 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 def create_grid_coords(polygon: Polygon, cell_size: float): # Define boundaries of grid @@ -174,7 +175,7 @@ def circle_polygon(): # Adds equally spaced points along an edge that is created after a polygon is cut. -def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: float): +def populate_new_edge(split_shape, cell_size: float, divisor: float): # Prepend new points onto the newly created edge to facilitate vertical splitting if split_shape is not None and polygon_min_x is not None: # Define starting point with an x-value that will be common for all polygons @@ -183,11 +184,9 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f # Create list of corners corners = [] - divisor_range = ((divisor - 0.1),(divisor + 0.1)) # Define tolerance NB: must find appropriate value - # Find all corners of split shape. Corner = point that intersects divisor for point in split_shape: - if divisor_range[0] < point[1] < divisor_range[1]: + if point[1] == divisor: corners.append(point) if not corners or len(corners) < 2: @@ -199,16 +198,9 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f while starting_point < sorted_corners[0][0]: # 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) - # Insert new points with cell_size spacing while starting_point is within bounds while starting_point < sorted_corners[-1][0]: split_shape.insert(0, (starting_point, divisor)) # NB may have to add/subtract small offset of 0.00001 - remaining_shape.insert(-1, (starting_point, divisor)) # Prepend new point to shape - starting_point += cell_size - return split_shape, remaining_shape - - + return split_shape