diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index 292074eece6f6c20639a8f1279a549c2c84d1952..fb8ec21176d8e459a50cb57a1e64c0b8458ef3d8 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 930381370a9f26761c8cd1891c1ee9363e7c59b1..7b411154a8030113cb9d0867e45659d316c4fba2 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -33,8 +33,8 @@ def get_relation(self, body_of_water: str): #hrz_lines = grid_lines[0] # Horizontal coordinates #vrt_lines = grid_lines[1] # Vertical coordinates - hrz_lines = [60.7530] # Horizontal coordinates - vrt_lines = [11.2267] # Vertical coordinates + hrz_lines = [60.7530, 60.5931] # Horizontal coordinates + vrt_lines = [11.0413] # Vertical coordinates # Cut polygon into horizontal sections for hrz_line in hrz_lines: @@ -43,38 +43,23 @@ def get_relation(self, body_of_water: str): cut_poly_1 = cut_polygon_in_two(polygon, hrz_line, True) polygon_part = cut_poly_1[0] # Save upper horizontal section - if not polygon_part or not cut_poly_1[0]: - continue - - # Cut each horizontal section into vertical sections - for vrt_line in vrt_lines: - cut_poly_2 = cut_polygon_in_two(polygon_part, vrt_line, False) - - 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] + divided_map.append(polygon_part) polygon = cut_poly_1[1] # Set polygon to the remaining, un-split shape for next iteration - # Split last remainder into horizontal lines - for vrt_line in vrt_lines: - last_section = cut_polygon_in_two(polygon, vrt_line, False) - - divided_map.append(last_section[0]) # Append part to final list of shapes - - # Set polygon_part to the remaining, un-split, horizontal section for next iteration - polygon = last_section[1] - - break # NB: temporary break to ensure treatment of only the first polygon + divided_map.append(polygon) tiles = gpd.GeoDataFrame(geometry=divided_map) - # NB: test plots + # NB test plot fig, ax = plt.subplots() ax.set_aspect(1.5) ax.xaxis.set_major_locator(ticker.MultipleLocator(0.2)) - tiles.plot(ax=ax, color='blue', edgecolor='orange', alpha=0.5, label='Original Polygon') + + for polygon in tiles['geometry']: + x, y = polygon.exterior.xy + ax.plot(x, y, color='blue', alpha=0.5) # Plot the exterior of the polygon + plt.show() # Convert GeoDataFrame to GeoJSON @@ -115,13 +100,17 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool): # Check if the split_shape has enough coordinates to create a polygon if len(split_shape) < 3: - print("Not enough coordinates to create valid polygon: Split shape") + print("Not enough coordinates to create valid polygon: Split shape: ", len(split_shape)) split_shape = None + else: + split_shape.append(split_shape[0]) # Append first coord to create closed loop # Check if the remaining_shape has enough coordinates to create a polygon if len(remaining_shape) < 3: - print("Not enough coordinates to create valid polygon: Remaining shape") + print("Not enough coordinates to create valid polygon: Remaining shape: ", len(remaining_shape)) remaining_shape = None + else: + remaining_shape.append(remaining_shape[0]) # Append first coord to create closed loop # Return split polygons as Shapely Polygon objects return Polygon(split_shape), Polygon(remaining_shape)