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

add: subdiv_id and subdiv_center

parent 41fb41c6
No related branches found
No related tags found
Loading
No preview for this file type
......@@ -28,8 +28,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water
polygon_counter = 1
num_of_polygons = len(polygons)
print("Dividing map... This may take a few minutes. As a reference, "
"a cell size of 0.01 takes approximately 13 minutes to complete.")
print("Dividing map... This may take a few minutes")
# Divide all polygons into sections
for polygon in polygons:
cell_size = 0.04 # NB smaller values require patience
......@@ -43,7 +42,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water
divided_map = combine_gird_with_poly(polygon, lines)
print("Polygon nr.", polygon_counter, " finished processing. ", num_of_polygons-polygon_counter,
print("Polygon nr.", polygon_counter, " finished processing. ", num_of_polygons - polygon_counter,
" polygons left to process.")
polygon_counter += 1
......@@ -51,13 +50,18 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water
tiles = gpd.GeoDataFrame(geometry=divided_map)
print("Plotting... This may take some time too...")
print("Adding ID's and center coordinates")
tiles['subdiv_id'] = range(len(tiles)) # Give each subdivision a unique ID
# Calculate the center coordinates of each tile
tiles['subdiv_center'] = tiles['geometry'].centroid.apply(lambda x: [x.x, x.y])
print("Plotting map...")
# NB test plot
fig, ax = plt.subplots()
ax.set_aspect(1.5)
# Plot the divided_map
tiles.plot(ax=ax, facecolor='none', edgecolor='black')
tiles.plot(ax=ax, facecolor='none', edgecolor='none')
for i, tile in enumerate(tiles.geometry):
random_color = "#{:06x}".format(random.randint(0, 0xFFFFFF))
......@@ -76,6 +80,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water
# Write GeoJSON to response object
self.wfile.write(tiles_json.encode('utf-8'))
def create_grid(poly: Polygon, cell_size):
# Retrieve bounds of the entire polygon
bounds = poly.bounds
......@@ -114,4 +119,3 @@ def combine_gird_with_poly(polygon, grid):
intersecting_tiles.append(intersection)
return intersecting_tiles
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