From 33b45233fa3f965c2d22ba67ee825cbf5e8641db Mon Sep 17 00:00:00 2001
From: Sara <sarasdj@stud.ntnu.no>
Date: Tue, 12 Mar 2024 11:39:37 +0100
Subject: [PATCH] update: only treat first polygon, still no work

---
 .../__pycache__/get_relation.cpython-311.pyc  | Bin 5307 -> 5443 bytes
 server/map/get_relation.py                    |  23 ++++++++++++------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc
index 9f6bc3bbed6c8498228339e917a9df921d086870..292074eece6f6c20639a8f1279a549c2c84d1952 100644
GIT binary patch
delta 532
zcmdn3d02~YIWI340}$*p_>ekZbR(ZCBV*HK6UJ+ddp2`3u`-Hsx-i6=)$*3`f)qhO
z4cp{}Ou~%(llhq?f#i86Sz-PZK1rA~LoHj6IU~blYi3PGfyt@Nn(TtLLN!7QxF;8~
zh)iC|EX*i0c`tJ~v%ms@$%?FElXY1ff$H*ER9S^<7#0YFRjp;|WENf^0b+0VWj({l
zzL;?jt5AvBW(D?5jEo|aFLTV{<;h7bE{QKrO)kmI&zqdbDaR@Tbb`X<37qO&o<J5S
z5Epk%KFHb5p~=ekfdNQN4&V}F{lLW_CObKkYq7he(gy}MPBk#m;c-`5cSZV!iUXn-
zrQNScyLb3J;1R#hBX@~MZbr=t$2s*EdGxRF=wIN`|G>r|uDrl-N`8lXhx-E#-pxwf
zp3IEalXLj=_^lLz3vx0`6pAwv3sS4>L1L3{^7*rQ0UcB1Jz0-GgfVV%Gyh#K?~5Eh
zS2%nwaQIBl5|9`4zsM1Ag(KhsN5Bm!xeorXY@25Z#4s`jP5v&Jz}UPwLP&y<I|^vV
zE#~5qq9V`9)xsu>Ig>XCPxK04WHelm{DA>PV<EGc6dA1+uzz3xQX5pk)PWE%g-&=)
I?iMis0Fm^RR{#J2

delta 488
zcmX@CwOf;KIWI340}#~fen_1pypd0pk<n_h3F9@!8JoG8SQ(jF7qCwjWD%MCfLEAt
z=HzB(O-BC7Yne6K1!@Ir1Q&2me#jy^`4h7cqu^v#mT+eN1p*+|Of`a&OIaL&Tp_UL
zvn>3KLX+>ZEMyegT+jN5kzLnW=Jlg(s+%*|H!(5_PnPDKqsUs4nUh+4i#aVby+{)1
zpj%vEf%vTA{Jdgepuptkoa$U2Kn5oe7l%)l;A&TtV^#UU03<rtzp^oiX{=!1VSGW<
z{-UV;6;b;Rt_PwrlMit%7ULAT&LMS)Lu!WkMGoaF9Lg8KX!9CwPi97&$=~?&1d6Q`
zf(vpoOB9MT5(`qR96*AM#gh~H{n<Q$wiS6z-o_uo7(AI<;I5U=MGoI99KIJgd~b+J
zb#MbM=HTwIzsN3qg<X0^;w5(Z3+(cDIe0Jd1zh9^yuuN9fg|vSlw1e@SB}j}f-#JY
zfs^Zn5*RBtKM;~&<c<WIev7%dq^QVaGP8&YWA<bVk%?ZejEsg0l0PtjXe?w1lM<uV
Y0`?CKKx%_3m^u&wrqBtW$-<%r0Ood&hyVZp

diff --git a/server/map/get_relation.py b/server/map/get_relation.py
index d6369636..93038137 100644
--- a/server/map/get_relation.py
+++ b/server/map/get_relation.py
@@ -30,8 +30,11 @@ def get_relation(self, body_of_water: str):
         # Divide the length and with of polygon into a grid
         grid_lines = create_grid_coords(polygon, cell_size=0.1)
 
+        #hrz_lines = grid_lines[0]  # Horizontal coordinates
+        #vrt_lines = grid_lines[1]  # Vertical coordinates
+
         hrz_lines = [60.7530]  # Horizontal coordinates
-        vrt_lines = [10.8572]  # Vertical coordinates
+        vrt_lines = [11.2267]  # Vertical coordinates
 
         # Cut polygon into horizontal sections
         for hrz_line in hrz_lines:
@@ -54,8 +57,16 @@ def get_relation(self, body_of_water: str):
 
             polygon = cut_poly_1[1]  # Set polygon to the remaining, un-split shape for next iteration
 
-        # Append last remainder
-        divided_map.append(polygon)
+        # Split last remainder into horizontal lines
+        for vrt_line in vrt_lines:
+            last_section = cut_polygon_in_two(polygon, vrt_line, False)
+
+            divided_map.append(last_section[0])  # Append part to final list of shapes
+
+            # Set polygon_part to the remaining, un-split, horizontal section for next iteration
+            polygon = last_section[1]
+
+        break # NB: temporary break to ensure treatment of only the first polygon
 
     tiles = gpd.GeoDataFrame(geometry=divided_map)
 
@@ -104,15 +115,14 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool):
 
     # Check if the split_shape has enough coordinates to create a polygon
     if len(split_shape) < 3:
-        print("Not enough coordinates to create valid polygons: Split shape")
+        print("Not enough coordinates to create valid polygon: Split shape")
         split_shape = None
 
     # Check if the remaining_shape has enough coordinates to create a polygon
     if len(remaining_shape) < 3:
-        print("Not enough coordinates to create valid polygons: Remaining shape")
+        print("Not enough coordinates to create valid polygon: Remaining shape")
         remaining_shape = None
 
-
     # Return split polygons as Shapely Polygon objects
     return Polygon(split_shape), Polygon(remaining_shape)
 
@@ -131,4 +141,3 @@ def create_grid_coords(polygon: Polygon, cell_size: float):
 
     # Return tuple of list of x coordinates and list of y coordinates
     return x_coords, y_coords
-
-- 
GitLab