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

update: rename tile to cell in add_new_lake

parent 5ab3e2b8
No related branches found
No related tags found
1 merge request!16Clhp map into main
......@@ -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)
......
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