From f2d90fc5321c8f9551e06032c0014a2f8f473f56 Mon Sep 17 00:00:00 2001 From: Sara <sarasdj@stud.ntnu.no> Date: Sun, 12 May 2024 21:29:07 +0200 Subject: [PATCH] update: rename tile to cell in add_new_lake --- server/map_handler/add_new_lake.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/server/map_handler/add_new_lake.py b/server/map_handler/add_new_lake.py index 90c8d248..6588cd11 100644 --- a/server/map_handler/add_new_lake.py +++ b/server/map_handler/add_new_lake.py @@ -33,8 +33,10 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5): bounds = polygons[0].bounds start_x, start_y, _, _ = bounds + # Calculate the cell width and height in degrees of latitude and longitude cell_width = cell_size_in_km / 111.3200 cell_height = cell_width / cos(start_x * 0.01745) + # List to store new GeoJSON feature objects features = [] # List to store new GeoJSON feature objects sub_div_id = 0 # Tracker to create unique subdivision ids @@ -45,7 +47,7 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5): # Generate a grid based on the calculated cell size lines = create_grid(polygon, cell_width * 2, cell_height) lines.append(polygon.boundary) - # Merge the grid lines into a single grid object + # Merge the grid lines into a single polygonized object lines = unary_union(lines) lines = linemerge(lines) lines = list(polygonize(lines)) @@ -53,16 +55,16 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5): # Combine the polygon and the grid to form the subdivisions for line in lines: if line.intersects(polygon): # Add the geometry which intersects the gird - tile = (line.intersection(polygon)) - divided_map.append(tile) + cell = (line.intersection(polygon)) + divided_map.append(cell) - # Calculate tile center based on bounds, and round down to two decimals - min_x, min_y, max_x, max_y = tile.bounds + # Calculate cell center based on bounds, and round down to two decimals + min_x, min_y, max_x, max_y = cell.bounds center = round(max_y - (max_y - min_y), 6), round(max_x - (max_x - min_x), 6) rounded_coordinates = [] - if isinstance(tile, Polygon): - for coords in tile.exterior.coords: + if isinstance(cell, Polygon): + for coords in cell.exterior.coords: rounded_coords = (round(coords[0], 4), round(coords[1], 4)) rounded_coordinates.append(rounded_coords) -- GitLab