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

update: sort lines before dividing map

parent 48da79a2
No related branches found
No related tags found
1 merge request!19Clhp map, license agreement
No preview for this file type
......@@ -66,6 +66,10 @@ def cut_map(cursor, lake_name: str, cell_size_in_km: float = 0.5) -> (int, str):
lines = linemerge(lines)
lines = list(polygonize(lines))
# Sort the lines to descending y values and ascending x values.
# This causes the processing to happen left to right, up to down.
lines.sort(key=lambda line: (-line.centroid.y, line.centroid.x))
# 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
......@@ -235,11 +239,19 @@ def plot_map(divided_map):
# Configure plot settings
fig, ax = plt.subplots()
# Start and end color
start_color = (0, 1, 0) # Green
end_color = (0, 0, 1) # Blue
num_steps = len(tiles)*1.3
print("len tiles: ", len(tiles))
# Plot each tile
for tile in tiles:
# Give each tile a random color to clearly visualize the grid
random_color = "#{:06x}".format(random.randint(0, 0xFFFFFF))
gpd.GeoSeries(tile.geometry).plot(ax=ax, facecolor=random_color, edgecolor='none')
for i, tile in enumerate(tiles):
color = [(start + (end - start) * i / num_steps) for start, end in zip(start_color, end_color)]
color_hex = "#{:02x}{:02x}{:02x}".format(*[int(255 * c) for c in color])
# Plot tile with the generated color
gpd.GeoSeries(tile.geometry).plot(ax=ax, facecolor=color_hex, edgecolor='none')
ax.set_aspect(1.8)
......
0, 60.765059, 10.528021
1, 60.752267, 10.531876
2, 60.758663, 10.53148
3, 60.745872, 10.532524
4, 60.739476, 10.530733
5, 60.764495, 10.536027
6, 60.758663, 10.535227
7, 60.741932, 10.540597
8, 60.745872, 10.540597
9, 60.752267, 10.540597
10, 60.758663, 10.540597
11, 60.765059, 10.540597
0, 60.769171, 10.528021
1, 60.763232, 10.52813
2, 60.763232, 10.539699
3, 60.757293, 10.539699
4, 60.757293, 10.53148
5, 60.751354, 10.539699
6, 60.751354, 10.532261
7, 60.745415, 10.532524
8, 60.745415, 10.539699
9, 60.741864, 10.539699
10, 60.739476, 10.530733
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