From 932a6b89ffecbea45cc868bfb82ed9be1cadac72 Mon Sep 17 00:00:00 2001 From: Sara <sarasdj@stud.ntnu.no> Date: Wed, 13 Mar 2024 19:45:53 +0100 Subject: [PATCH] update: perhaps some improvement --- .../__pycache__/get_relation.cpython-311.pyc | Bin 7972 -> 7771 bytes server/map/get_relation.py | 30 +++++++----------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index 78b81d93f4fc4f5ee3a9312d3d738fd2d380ea23..96f80953ff49aec41eb8a8c82da8bd1bc35362b4 100644 GIT binary patch delta 1021 zcmah{Ur1A76hGhH?!9w=?xvd?Zf^5Wb1ec>lu=kjC5=HwXp)eWxfSNbbvMJ}TPg(Y z!6^A26nbct*-(SkUU~_Hq#k<NWW=bKUVQ24Mm^M9-#1&Di5)n<-#LdL=g<A_{E<%` z(ldiW3)BMNzlO2<g>;t}SqktY`<Q>np<!}WQ!jXUNdXU;(X<$B6-^3INCws&2eNsM zpF@k;3f+FyaSo#e6~Gep4NGXTc8bH=ggS06*8nh&|5fU+jw*H8i1Yv<J<*s3JjUo~ zbSyFu4~H(qqLHEaN5f`84v)n2v}GNcFxiDZ8pW<>ADYsr-L^Na%k-^?d266x4NRUc ziq@RiP_%lIx^;^uHJZ7x;>}xv1xs-9R8h3##JZy0n~hZ+<j}qBbBmEf1LU>Uj(SPa zdIvos7j3J9e-5H^c<L<wHje;i0mIb$I8Dno^>%BPP+ft98p8?bZ%pu*522c}5HL5) zu|%%M>J%a~dNcVcRcaAT@4;%>9Op??a!!=wG8ckwi2r^VR>JC#>NYH^7if#6QX5uH z2v~)M5WhKOYdp*(Als-0-84|O>i_C}873D(!mcfwF{IS&f_@0`RL@=J{$32hwxPTB z%g}z^z)oiF6T9RJw)h~qW*<kZ<cr;HU?<C+6nwngLn<9El_&>^-{B=A4%>P5q3SkF zKFXAVGQ6Zg%tc>r5<ZJnInnj>aIUdqy{0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j*T2>Y9|W=Ju;y_nOiTnXaczT5Vg( z1_`HMN5uLOyki3I_~eS+J992?_o*MG@uPj3{Rn)^1x#O92<4kLoMHlyjeC+<Vy`{T zJ)Rfho@H^5+MJda1g+tCPVCH!otoIWCc0;$Ik6$tt6P!1Zsx1>aNZZn`18J&WvNAz zT67UPJTqrC`vJ{zK<~orl=m**Zyc<Tz48WejM?fQ_H<($Qb%-T*llot9K!8ttB$~A j`U__9YQek@m)Lq;^Pzg&xBz)DzZOklydB6NLn&_oHwY(U diff --git a/server/map/get_relation.py b/server/map/get_relation.py index b3a36328..40bccf0d 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -19,7 +19,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water # Divide all polygons into sections for polygon in polygons: - cell_size = 0.4 + cell_size = 1.5 # Divide the length and with of polygon into a grid of equally sized parts grid_lines = create_grid_coords(polygon, cell_size) @@ -28,7 +28,6 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water # Cut polygon into horizontal sections, bottom to top for hrz_line in hrz_lines: - # Split shape into upper and lower section as hrz_line as divider divided_poly = cut_polygon_by_points(polygon, hrz_line, cell_size) horizontal_section = divided_poly[0] # Save upper horizontal section @@ -122,10 +121,13 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float): remaining_shape.append((point2.x, point2.y)) # Populate newly created edges with points to facilitate vertical cutting - populated_shapes = populate_new_edge(split_shape, remaining_shape, cell_size, divisor) - if populated_shapes is not None: - split_shape = populated_shapes[0] - remaining_shape = populated_shapes[1] + populated_split = populate_new_edge(split_shape, cell_size, divisor) + if populated_split is not None: + split_shape = populated_split + + populated_rem = populate_new_edge(remaining_shape, cell_size, divisor) + if populated_rem is not None: + remaining_shape = populated_rem # Ensure that the shapes are closed loops if len(split_shape) > 0 and split_shape[0] != split_shape[-1]: @@ -137,7 +139,6 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float): 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 def create_grid_coords(polygon: Polygon, cell_size: float): # Define boundaries of grid @@ -174,7 +175,7 @@ def circle_polygon(): # Adds equally spaced points along an edge that is created after a polygon is cut. -def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: float): +def populate_new_edge(split_shape, cell_size: float, divisor: float): # Prepend new points onto the newly created edge to facilitate vertical splitting if split_shape is not None and polygon_min_x is not None: # Define starting point with an x-value that will be common for all polygons @@ -183,11 +184,9 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f # Create list of corners corners = [] - divisor_range = ((divisor - 0.1),(divisor + 0.1)) # Define tolerance NB: must find appropriate value - # Find all corners of split shape. Corner = point that intersects divisor for point in split_shape: - if divisor_range[0] < point[1] < divisor_range[1]: + if point[1] == divisor: corners.append(point) if not corners or len(corners) < 2: @@ -199,16 +198,9 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f while starting_point < sorted_corners[0][0]: # Increment starting point until it is withing the polygons bounds starting_point += cell_size - # if starting_point < left_corner.x: # NB: optimised substitute for previous while loop, requires testing - # starting_point += cell_size * math.floor(starting_point - left_corner.x) - # Insert new points with cell_size spacing while starting_point is within bounds while starting_point < sorted_corners[-1][0]: split_shape.insert(0, (starting_point, divisor)) # NB may have to add/subtract small offset of 0.00001 - remaining_shape.insert(-1, (starting_point, divisor)) # Prepend new point to shape - starting_point += cell_size - return split_shape, remaining_shape - - + return split_shape -- GitLab