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

add: interior polygons

parent 99426241
No related branches found
No related tags found
1 merge request!16Clhp map into main
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -5,7 +5,7 @@ from math import cos
import geopandas as gpd
from matplotlib import pyplot as plt
from shapely.ops import linemerge, unary_union, polygonize
from shapely.geometry import Polygon, LineString, MultiLineString
from shapely.geometry import Polygon, LineString, MultiLineString, MultiPolygon
from server.consts import LAKE_RELATIONS_PATH
......@@ -26,6 +26,11 @@ 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']
polygons = [Polygon(polygon.exterior) for polygon in polygon_data['geometry']]
interior_polys = []
for polygon in polygon_data['geometry']:
for interior in polygon.interiors:
interior_polys.append(Polygon(interior))
if len(polygons) <= 1:
raise Exception("Failed to convert JSON object to Shapely Polygons")
......@@ -42,7 +47,7 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5):
# Process all polygons
for polygon in polygons:
# 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)
# Merge the grid lines into a single grid object
lines = unary_union(lines)
......@@ -52,6 +57,9 @@ 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
divided_map.extend(combine_grid_with_poly(polygon, lines))
# Add interior polygons
divided_map.extend(interior_polys)
# List to store new GeoJSON feature objects
features = []
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
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