From 966cfcf14390a69d988ae22ec1ae67bc0f01719e Mon Sep 17 00:00:00 2001
From: Sara <sarasdj@stud.ntnu.no>
Date: Tue, 12 Mar 2024 11:02:15 +0100
Subject: [PATCH] update: minor progress

---
 .../__pycache__/get_relation.cpython-311.pyc  | Bin 5446 -> 5477 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 0921934ff5aa4d9b7fbf3b1355ce5214446579e6..5c05e2e26388e10266f5a9b6247b53d327a24bbb 100644
GIT binary patch
delta 347
zcmX@6^;C;*IWI340}y;v|B$LIvXM`fk<n_h3F9@!8I!r0Oc~QBJ2Lq*noXX_q{_^?
zfPL~tW|7JFne@fYYq(SRBtaU%pq8yCqXs5_mPeRz=4NH)tIYhXK3?)oO7L??*L9Y8
z{b<`}cJ_r#jNy}4a_(Xi;#B#-AT&9X%T}6=SN8)0keI-6S5|)m&yI`}tQTeduE_dL
z;F^4a%TSt)fm7r<htwqwsTt-MIh3z(C|>}hr#$?dxwx;hFvf3w#Lvjc`jw4=gM0Hc
zfq#q&H9%(-mjj6gh6jooOXM!H$Thfjm`+fgAqrF_AhelD_%&msDx=i`_74m|YJ)16
dIuHV;(1{>M9!5EkN+7kt6-?nIibR060swVhVq*XR

delta 343
zcmaE=bxezIIWI340}!~XeMn6b-pHrQ$fz{ggz*|<&tz^UQ^tbHj!gcH_LC<vsS5I?
z@JND`f<ZB3kIZC#X35FtnDj&)YPeJQ5OTF_J%v5Jo2{9zGV_0yzmy*z@8^*ICUA#b
z>+8+(><gI~Lna^O+{Gr!sq%qAbaEq?trjP*?gs`SF@fW*to{a`9T_KBFUtB|k@cIv
z^*~&4f#Q_f4-AZgvNuFzCg0>T<kSXg{i?^nE3jFW`#K9_?B>7xjEu}r*||0|3;tu2
zt_HfWxD-e<Fx*hoSR!|kMXtfM!*qh`4AIGk!or&kg>N%PsxVqDVE@1Xq&BF6sRJQk
Z3Y`dG<YbfssRU9RT)`AhqDTa2DFBZ8T`m9s

diff --git a/server/map/get_relation.py b/server/map/get_relation.py
index d792f787..8e240247 100644
--- a/server/map/get_relation.py
+++ b/server/map/get_relation.py
@@ -30,8 +30,8 @@ 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 = [60.7451]  # Horizontal coordinates
-        vrt_lines = [10.9600]  # Vertical coordinates
+        hrz_lines = [60.7530]  # Horizontal coordinates
+        vrt_lines = [10.8572]  # Vertical coordinates
 
         # Cut polygon into horizontal sections
         for hrz_line in hrz_lines:
@@ -47,9 +47,6 @@ def get_relation(self, body_of_water: str):
             for vrt_line in vrt_lines:
                 cut_poly_2 = cut_polygon_in_two(polygon_part, vrt_line, False)
 
-                if not cut_poly_2[0]:
-                    continue
-
                 divided_map.append(cut_poly_2[0])  # Append part to final list of shapes
 
                 # Set polygon_part to the remaining, un-split, horizontal section for next iteration
@@ -57,6 +54,9 @@ 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)
+
     tiles = gpd.GeoDataFrame(geometry=divided_map)
 
     # NB: test plots
@@ -102,13 +102,14 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool):
             else:
                 remaining_shape.append(point)
 
-    # Check if polygons have enough coordinates
+    # 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")
         split_shape = None
     else:
         split_shape.append(split_shape[0])  # NB: may not be necessary?
 
+    # 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")
         remaining_shape = None
@@ -121,7 +122,10 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool):
 
 # Generate grid of equally spaced x and y coordinates where the grid size is determined by cell_size
 def create_grid_coords(polygon: Polygon, cell_size: float):
+    # Define boundaries of grid
     min_x, min_y, max_x, max_y = polygon.bounds
+
+    # Divide grid into sections of size *cell_size
     x_coords = np.arange(min_x, max_x, cell_size)
     y_coords = np.arange(min_y, max_y, cell_size)
 
-- 
GitLab