Skip to content
Snippets Groups Projects
Commit d76e565d authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

update: simplify add new lake logic

parent 3412422c
No related branches found
No related tags found
1 merge request!16Clhp map into main
No preview for this file type
......@@ -49,8 +49,12 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5):
lines = linemerge(lines)
lines = list(polygonize(lines))
# Divide the polygon into tiles based on the generated grid
divided_map.extend(combine_grid_with_poly(polygon, lines))
# Combine the polygon and the grid to form the subdivisions
for line in lines:
if line.intersects(polygon):
divided_map.append(line.intersection(polygon))
break # NB test break
# List to store new GeoJSON feature objects
features = []
......@@ -160,32 +164,6 @@ def create_grid(poly: Polygon, cell_width: float, cell_height: float):
return grid_lines
def combine_grid_with_poly(polygon, grid):
"""
Returns a list of polygons that together make up map tiles.
Parameters:
polygon (Polygon): A polygon representing a map or part of a map
grid (list): List of LineString objects defining the grid
Returns:
intersecting_tiles (list): List of Polygons
"""
# List to contain all the tiles
intersecting_tiles = []
for line in grid:
if line.intersects(polygon):
intersection = line.intersection(polygon)
# Check if intersection is a MultiLineString
if isinstance(intersection, MultiLineString):
# Extend the intersecting tiles with the polygonized results
intersecting_tiles.extend(list(polygonize(intersection)))
else:
intersecting_tiles.append(intersection)
return intersecting_tiles
def write_json_to_file(lake_name: str, map_data: dict):
"""
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment