diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index 68c0cc6a2c8de1d9bad2c4a677526c0144087a78..78b81d93f4fc4f5ee3a9312d3d738fd2d380ea23 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 81f7ce5f73a028319021e576f52c5c58fa75227e..b3a363289816a93defbf52b3b605a5cad41f7c33 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -44,7 +44,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water 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) + vertical_parts = cut_polygon_by_points(horizontal_section, vrt_line, cell_size) divided_map.append(vertical_parts[0]) # Append split vertical sections to final list of shapes @@ -121,6 +121,12 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float): else: 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] + # Ensure that the shapes are closed loops if len(split_shape) > 0 and split_shape[0] != split_shape[-1]: split_shape.append(split_shape[0]) @@ -181,23 +187,23 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f # Find all corners of split shape. Corner = point that intersects divisor for point in split_shape: - if divisor_range[0] < point.y < divisor_range[1]: + if divisor_range[0] < point[1] < divisor_range[1]: corners.append(point) if not corners or len(corners) < 2: return None # Sort corners in ascending order (left to right) based on x coordinate - sorted_corners = sorted(corners, key=lambda p: p.x) + sorted_corners = sorted(corners, key=lambda p: p[0]) - while starting_point < sorted_corners[0].x: # Increment starting point until it is withing the polygons bounds + 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].x: + 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