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

update: rollback some of the division logic

parent d3c829f0
No related branches found
No related tags found
1 merge request!16Clhp map into main
No preview for this file type
...@@ -4,8 +4,8 @@ import random ...@@ -4,8 +4,8 @@ import random
from math import cos from math import cos
import geopandas as gpd import geopandas as gpd
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from shapely.geometry import Polygon, LineString, MultiLineString
from shapely.ops import linemerge, unary_union, polygonize from shapely.ops import linemerge, unary_union, polygonize
from shapely.geometry import Polygon, LineString, MultiLineString
from server.consts import LAKE_RELATIONS_PATH from server.consts import LAKE_RELATIONS_PATH
...@@ -26,15 +26,6 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5): ...@@ -26,15 +26,6 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5):
polygon_data = geo_data[geo_data['geometry'].geom_type == 'Polygon'] polygon_data = geo_data[geo_data['geometry'].geom_type == 'Polygon']
polygons = [Polygon(polygon.exterior) for polygon in polygon_data['geometry']] polygons = [Polygon(polygon.exterior) for polygon in polygon_data['geometry']]
# Extracting interior polygons to preserve fully enclosed islands
interior_polys = []
for polygon in polygon_data['geometry']:
for interior in polygon.interiors:
if isinstance(interior, Polygon): # Only include Polygon objects
interior_polys.append(interior)
all_islands = polygonize(interior_polys)
if len(polygons) <= 1: if len(polygons) <= 1:
raise Exception("Failed to convert JSON object to Shapely Polygons") raise Exception("Failed to convert JSON object to Shapely Polygons")
...@@ -45,13 +36,13 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5): ...@@ -45,13 +36,13 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5):
bounds = polygons[0].bounds bounds = polygons[0].bounds
start_x, start_y, _, _ = bounds start_x, start_y, _, _ = bounds
cell_width = 0.5 / 111.3200 cell_width = cell_size_in_km / 111.3200
cell_height = cell_width / cos(start_x * 0.01745) cell_height = cell_width / cos(start_x * 0.01745)
# Process all polygons # Process all polygons
for polygon in polygons: for polygon in polygons:
# Generate a grid based on the calculated cell size # Generate a grid based on the calculated cell size
lines = create_grid(polygon, cell_width * 2, cell_height) lines = create_grid(polygon, cell_width*2, cell_height)
lines.append(polygon.boundary) lines.append(polygon.boundary)
# Merge the grid lines into a single grid object # Merge the grid lines into a single grid object
lines = unary_union(lines) lines = unary_union(lines)
...@@ -61,9 +52,6 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5): ...@@ -61,9 +52,6 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5):
# Divide the polygon into tiles based on the generated grid # Divide the polygon into tiles based on the generated grid
divided_map.extend(combine_grid_with_poly(polygon, lines)) divided_map.extend(combine_grid_with_poly(polygon, lines))
# Add islands as the last object
divided_map.extend(all_islands)
# List to store new GeoJSON feature objects # List to store new GeoJSON feature objects
features = [] features = []
......
[ [
"Mjøsa", "Mjøsa",
"Skumsjøen" "Skumsjøen",
"Mjsa"
] ]
\ No newline at end of file
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