diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index 6d7c237fe1158ac5b62ed78021efb4298eee0deb..b358dc3736955c52454f2a9a260eaad50c0aa21b 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 e97ffba0d0ed1b276e06b4db9e8147ebe67f78a6..a4de972437fc229a24221c51d59ebe598d0253c2 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -27,22 +27,22 @@ def get_relation(self, body_of_water: str): # Divide all polygons into sections for polygon in polygons: + cell_size = 0.1 # Divide the length and with of polygon into a grid of equally sized parts - grid_lines = create_grid_coords(polygon, cell_size=0.1) + grid_lines = create_grid_coords(polygon, cell_size) vrt_lines = grid_lines[0] # Vertical grid coordinates hrz_lines = grid_lines[1] # Horizontal grid coordinates - for line in vrt_lines: - print("Line: ", line) - # 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_in_two(polygon, hrz_line, True) + divided_poly = cut_polygon_in_two(polygon, hrz_line, cell_size) horizontal_section = divided_poly[0] # Save upper horizontal section + polygon = divided_poly[1] # Set polygon to the remaining, un-split shape for next iteration + if not horizontal_section or not divided_poly[0]: continue @@ -52,15 +52,13 @@ def get_relation(self, body_of_water: str): break # Break from loop im remaining section has no coordinates # Split the horizontal section into two vertical parts - vertical_parts = cut_polygon_in_two(horizontal_section, vrt_line, False) + vertical_parts = cut_polygon_in_two(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] - polygon = divided_poly[1] # Set polygon to the remaining, un-split shape for next iteration - divided_map.append(polygon) break @@ -95,7 +93,7 @@ def get_relation(self, body_of_water: str): # Takes a polygon and divides its coordinates into two shapes, where divisor is a # coordinate that defines the point of division -def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool): +def cut_polygon_in_two(polygon: Polygon, divisor: float, cell_size: float): # Extract polygon exterior coordinates exterior_coords = list(polygon.exterior.coords) @@ -104,14 +102,31 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool): remaining_shape = [] # Loop through points and check which side of the division line they are - for point in exterior_coords: - point = Point(point) # Convert coordinates to Shapely Point object - if horizontal: # Horizontal split + if cell_size > 0: # Horizontal split + for point in exterior_coords: + point = Point(point) # Convert coordinates to Shapely Point object if point.y < divisor: split_shape.append(point) else: remaining_shape.append(point) - else: # Vertical split + + if len(split_shape) > 2: + # Get last point added to + last_point = split_shape[len(split_shape)-1] + # Get length of the newly created edge + new_edge_len = last_point.x - split_shape[0].x - 0.0001 + print("new_edge_len: ", new_edge_len, " cell_size: ", cell_size) + + # Add points along the new edge to allow horizontal sections to be split into vertical ones + while new_edge_len > cell_size: + print("Hit") + split_shape.append((new_edge_len-cell_size, last_point.y)) + remaining_shape.append((new_edge_len-cell_size, last_point.y)) + new_edge_len -= cell_size + + else: # Vertical split + for point in exterior_coords: + point = Point(point) # Convert coordinates to Shapely Point object if point.x < divisor: split_shape.append(point) else: