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 zcmZ`#Ur19?7{A}{?(W&{pXuGdytnQo)Yx7m=_M6g4+cU@Z><N3(8ZOttU0Ga>6TBy z9u`>Niw{B?q=G(Jd+{*{dK0#FX+{LT6hu)<^ctPJ5=7|0`F`hozu))$zH?qj-bCe9 zN%Ams^>^%z-SEAT+W}7E8F&XJ6dY|H)186>F+C~3xT7;5w%FRnDu{V8NAiLx;$z3D zfV9Fg%sSowSUE3KX4??~5zotNj9%r##ibZ6J)CisCQFZ|;h+J-+#(0(Jh$ORgS`q( zxXKPdGw!ozy^85G{bpbzxWZ9m4h=bogU)LZ!gXhaJ!ZCG-8ls+)#@&jxxz%W@&vaC zdg^DmHZd}CDVF+XZ0Qfbw#O1V2X(se#rDP!|D8={vt>e_0VHtUy&?pT&kq#cJ2sR@ zJs$ubV6S+OciQ9Sg7`yfc_JzJS?oQUN=Swyr{J~}=9q#rqfw~_Ed34**Q7R9nQq3X zpn8BYnF5#5@*M6<A(k_3$q4k~vfSzKZoQJdot|!;x|z(5H3prD*+g@9>*cXK$#f>2 zN&O}9y?lbpb=Z&iEziProbkS$`$(jUe6dR67Kv9#d?%<Dg`%)ae08GMh`P|TG`ZMU zB~gn+D<t}f_Y}`ndClUrg=CEnSNL$F!BCYL7BMQs*irSOx9Hs^p*qoPL|>R&o3z5G ztE9^!T@}*x%f*Pk`JSo}wuJEWP`TVR2w)(qjJjs&WK(xBt&DSfROQFIvJAs`-`5A@ oxaE5}+y>oC{2oJLv%LYY5)C*ShQJNFt)#Ho-+=#yoS(Y>0j0&q*8l(j delta 661 zcmZ`!O=uHQ5Z>8++3Y6!)BM&%$R0G26if(}mMWSYwBW%&Z3P<z4Q>Rr+BO@s+Knd< zJ>(!vu{|iH9;#x&YEIrN1<y$gHbe?m@t_CET@SupEe62{Z@&57H}lQBw*#AT<%ul2 z7<xYM>lQY=FO?|35FUc}@BrQH{)p++#gL`jrz}wJ`pa>IO$K^($&`wM>DEOovj+mw zD#tL->HX8Km<m;1vvCk{M-FEw?J+A$l?-j|ec>y!m8BBw8ZgXNVK+A&Ycd|?&VYi* zodgxPxe>8X_vl{Tx8_HU+=2iukvJFB`*D*Pu!mMec%2z%;-T6($3u{cEH(RTxlfE@ z!1<jk%#~`q@EG7MJ`-0}e`I-f@zjFY{+-lvt`C+pB+UVXFQn^sOkq|YV+|kvkfY$i z6<Kp|<BUmgOz!81POOjOjuhe?G|wv+Ac=33WFpRHv-bSBt3#%)7^R|0_vrAKrl*U# zQ6v_D+Z{eXGgG*s<7IUoj^iiw-T6mGHQmq#TiW1yzNrn@wc%|+t}E$=kZB2-x{ztB zp@lnLo^kYTkzkVq@6T6Li+39&)*`VwiM5Gui-embyqtcTYVAGPAc+=9)Jfut+gls( zOah$7d)|xuO}c?$;5Y9z?xWj>Io}H8@Tcz>OyLp#t4R$GSDjsk!g|z(jR_n64Wl4H R#HysQe!_<ThN7R&{003|srCQ> 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