From 3b38bdf73aa9ec08410dea5c56d9cb47ea204e6b Mon Sep 17 00:00:00 2001
From: Sara <sarasdj@stud.ntnu.no>
Date: Thu, 14 Mar 2024 11:32:03 +0100
Subject: [PATCH] add: subdiv_id and subdiv_center

---
 .../__pycache__/get_relation.cpython-311.pyc  | Bin 4864 -> 5237 bytes
 server/map/get_relation.py                    |  16 ++++++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc
index 7093df81dd8e6ae620eb9701e3bdc1063698d730..94d100007332813dbf0f83044e989f98f48831da 100644
GIT binary patch
delta 1169
zcmZuu&1)M+6rYi2ZR>OO;mDPxbv72ZBMYPiS}X_K!BD475BYMFlu!t3%~nV#D`$6|
z+GZ0gCI>@u33CXAwrnp>i*wT-&`S@7hM*0Cz?PO=LLeuT($e;nH{K}5C69d{^M3C)
zZ{EJ<*k4B@55wUA0<oOe>JQ@m$lv(KmVod2B4!^?dtwFID<Lyt1!-g&GT?owE{1Ai
zH?*T{&X@QEQSlDi!U%1HdIF3nXPW+Q1|b?dSc8$7-A8M2wo8(sFMSBz4BZS{VLQPu
zA4D|%f0`Av2RN2PR+uJe;?clX4>Sk$1TM~ZWB&MBlI;pfc8r934%vg8DI)Xuenl<C
zYQhk+h?E}cW-akx*Zq!G^nD%geQ{uzGz^o*8QzN>76!1i7rhi>y%<@@9_GgsqA5DG
z1p{w`da{QeeoGUh{8*E_pnZe`0<vQE2#<OYO~anDIMa&sE@GT#*ZcD9kG>1*BXg8i
zwTgWD<8eb)G%A->%~W-{+-T?kD5h$-eq(u&R&QLb((=2tK_~u{1n8f`U>@-P;5~u(
zU1i0$fPTVfay}QYxOg>(^+6~yI4<k!QE>nDPuG=ei&U9i8?LD4Rb8zsX0@Rert6Ke
zQa5HH@bD66M!+=DPV8}FM|oV{2{e%&hm;$B`%G_wHSt`%VVZolYsylgP^dr+$Ui4t
zqBS%%*W>z>74~)i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THdVjKvyjju_h*FFzh#HIG^NjonDX<ffihA
zp`yk{g{!nIDZT-&ak$lZDQ&_Nvy8G@K25iYX_1_5wE};+X6PoS=OcshIi5Dpz!Df>
zZl=V~;x6QACGwEn``5^Vm;a?^g3iftKmQ6&KQm4r%l+^k-Ih1-G=yWd+yUUv|KJRr
Hj86OksxZTG

diff --git a/server/map/get_relation.py b/server/map/get_relation.py
index 84815af0..ec017cbb 100644
--- a/server/map/get_relation.py
+++ b/server/map/get_relation.py
@@ -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
-
-- 
GitLab