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

fix: cell formula again, now final

parent cfebc035
No related branches found
No related tags found
1 merge request!16Clhp map into main
No preview for this file type
...@@ -33,17 +33,17 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5): ...@@ -33,17 +33,17 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5):
# List to store all the map tiles # List to store all the map tiles
divided_map = [] divided_map = []
# Convert the cell size to degrees # Select an arbitrary x and y value from within the polygon
cell_size = cell_size_in_km * 2 bounds = polygons[0].bounds
cell_width = cell_size / 111.32 start_x, start_y, _, _ = bounds
# A slightly more complicated formula is required to calculate the height. This ensures that
# the height in km is equal to the width in km regardless of the latitude. cell_width = cell_size_in_km / 111.3200
cell_height = (cell_size * 360) / (40075 * cos(cell_width)) 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, 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)
...@@ -233,7 +233,6 @@ def plot_map(divided_map): ...@@ -233,7 +233,6 @@ def plot_map(divided_map):
# Configure plot settings # Configure plot settings
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.set_aspect(1.5)
# Plot each tile # Plot each tile
for tile in tiles: for tile in tiles:
...@@ -241,5 +240,7 @@ def plot_map(divided_map): ...@@ -241,5 +240,7 @@ def plot_map(divided_map):
random_color = "#{:06x}".format(random.randint(0, 0xFFFFFF)) random_color = "#{:06x}".format(random.randint(0, 0xFFFFFF))
gpd.GeoSeries(tile.geometry).plot(ax=ax, facecolor=random_color, edgecolor='none') gpd.GeoSeries(tile.geometry).plot(ax=ax, facecolor=random_color, edgecolor='none')
ax.set_aspect(1.6)
# Display plot # Display plot
plt.show() plt.show()
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