From 4e580b52e08d747d321b409d1ce36b13dcdfdf9c Mon Sep 17 00:00:00 2001 From: Sara <sarasdj@stud.ntnu.no> Date: Tue, 12 Mar 2024 10:54:40 +0100 Subject: [PATCH] update: minor progress, part of map --- .../__pycache__/get_relation.cpython-311.pyc | Bin 5315 -> 5446 bytes server/map/get_relation.py | 30 +++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index 76c8ff54db3931e76b092b850b48ecad05d4aa01..0921934ff5aa4d9b7fbf3b1355ce5214446579e6 100644 GIT binary patch delta 745 zcmX@Cc}$CMIWI340|NtttJ;UuB;k#Gs*H?ElT8?}G4@R6W>Vow;Y??&<w)U5XPoTI zq%X=N2~rEjwLCREMI1HUDLj)WGO3I5E@Nh3Sj`NUVqjpX<*VUK;hB7vNt2OhvLm0A zLk(XFAF}2ihZ=4a5w@Pfp578hm;nq7SsXBS4eJ{I$$`wFi~^IFGkY=$PX5Sj$uE>5 zoFbAUx<+gnD+9x7*2#f<Vw3$@q8Y^}uV&F?mPnDDe4VA3QEKu>W;wPLhF}Iw>CO49 za~S2)Kg(arkB|3rNPiQ!L$39;szXQ-69WT-+e?t$lf~KJF((!jZ06ut#K;&jc{S%U zZc&*Do*kSwK-A_0uG@@^b(3v)D%e>-&MOj|{GL~G60gwYXFN9OLLt0?OhrPI&+^K% zGSsr<Nl$*yE6vC}*^y6r@(NxRW}y<n$@3YdxEL8y7;0Jbq-$6wf8-TsW=#PpiD$H# zypT^{#7ZH!ASbg#p*SP4AQkM;DhH5+pp`;UYHng?US?i8L~`;?K3UcxH3kNT$^ZDO z8Dl3`@n5dL%fWkr&*vhC?-dT;3mm>T#H2d7JGdWk2w&%ry2K$h!+JsC9J`AgT30x< zE^uf)W#{U!zsN3qg<X0^;w5(Z3+(b>0|G8`1YY3?yucB7LrSiLzk~k)hxm04xl0^! zGwN3qUXeGv$YFGa!{`Es(N{JG9^nbr7rEuHaLX?h-@IACpOG<eGP6(uTQvg%LviWk zOrdPn4{QuPB9pHREo6+GTq$hFm_2!i@TN!=Mymzv9~e{^tv0BFsRJQk3Y`dG<Ybfs XspMpo+u-_vfs;`VCs8EAz`y_irNzhB delta 661 zcmX@6by$;cIWI340|NuYW91L22ZT2AsWLK}O*Ub?#yD*<H<OB74SNcwBuE~NYdLDz zQ@9ZP$(Bs|qR8?*H9SQeHQXtjlWUpOMR}GnGcc@X25V(tV5sG*;Y;D1ypu_jk#q7x zUMYtfK4imcd3qdbxKTvddJ21{moUN%U|`7NfU#>>*YHlZWe#QJn>?A>laYV&U1m#8 zffT_Mp%mdYB9rA=${9r`PiN6&7E2MIe3+$}QDX94W;wPLhF}Iw$<5KMa~OGwm>3us zUV=;yahoj4{*F1dqGU50$0A0?h{-ECm+_0p%_yAW+rfDQ!q^<ebsHpQ##6z_FnK*s zE|@f&?8h6(R4hFCH?JzA;N*q8@~q6k3^gp119`=nSyEU)9-aJ<N0ON}g=KOgUp%A! z<b!<rdYVjreqj4Gxo)xKWEPhc@iQ<m++s`4&o4?TE@A<37%OkFB^DH<=A}$d<F96P znf!?Va?IS~1@;%^jjzZXZ%Di(Z+=1E{4NLY1wQ+W91d4F94>G;+~Ak&sQSRhz$$Q^ zMeGub*o5i@hEwV;vZ!5QQM<sRc7sLuI*ZgL7O5HbD-5ql>t1BhyTYP(fkp2rx6o!S z!AM5Npvf&l32bEy3=GA^lV1sCGe6)Ko*X5-kTGiVA7MMjoXOTAn<C{ItroC<V323D m+Mo)i4upUybi$31gHaBol7mrhgX;$d4n{egM3D#s0|Nm4QmOU; diff --git a/server/map/get_relation.py b/server/map/get_relation.py index 15d0590e..d792f787 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 = grid_lines[0] # Horizontal coordinates - vrt_lines = grid_lines[1] # Vertical coordinates + hrz_lines = [60.7451] # Horizontal coordinates + vrt_lines = [10.9600] # Vertical coordinates # Cut polygon into horizontal sections for hrz_line in hrz_lines: @@ -50,7 +50,7 @@ def get_relation(self, body_of_water: str): if not cut_poly_2[0]: continue - divided_map.extend(cut_poly_2[0]) # Append part to final list of shapes + 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 polygon_part = cut_poly_2[1] @@ -92,26 +92,31 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool): for point in exterior_coords: point = Point(point) # Convert coordinates to Shapely Point object if horizontal: # Horizontal split - if point.y < divisor: + if point.y > divisor: split_shape.append(point) else: remaining_shape.append(point) else: # Vertical split - if point.x < divisor: + if point.x > divisor: split_shape.append(point) else: remaining_shape.append(point) # Check if polygons have enough coordinates - if len(split_shape) < 3 or len(remaining_shape) < 3: - print("Not enough coordinates to create valid polygons") - return None, None + 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? - # Append the first coordinate of the shapes to create closed loop - split_shape.append(split_shape[0]) # NB: may not be necessary? - remaining_shape.append(remaining_shape[0]) + if len(remaining_shape) < 3: + print("Not enough coordinates to create valid polygons: Remaining shape") + remaining_shape = None + else: + remaining_shape.append(remaining_shape[0]) - return Polygon(split_shape), Polygon(remaining_shape) # Return split polygons as Shapely Polygon objects + # Return split polygons as Shapely Polygon objects + return Polygon(split_shape), Polygon(remaining_shape) # Generate grid of equally spaced x and y coordinates where the grid size is determined by cell_size @@ -123,5 +128,6 @@ def create_grid_coords(polygon: Polygon, cell_size: float): if len(x_coords) == 0 or len(y_coords) == 0: raise ValueError("No grid points generated") + # Return tuple of list of x coordinates and list of y coordinates return x_coords, y_coords -- GitLab