From 3aeee368f0aaeab72ad55862ec84121807f5bb44 Mon Sep 17 00:00:00 2001 From: Sara <sarasdj@stud.ntnu.no> Date: Wed, 13 Mar 2024 13:31:46 +0100 Subject: [PATCH] update: horizontal sections without spacing --- .../__pycache__/get_relation.cpython-311.pyc | Bin 7480 -> 7817 bytes server/map/get_relation.py | 72 ++++++++---------- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index b60cf86f63fea40cec5c55d8ee98c439fd98b3da..68c0cc6a2c8de1d9bad2c4a677526c0144087a78 100644 GIT binary patch delta 2241 zcmb7ETTB~A6rEk$yKB6**D?4>alizJR}eusU>+$UP12^2L>B2INfUxG5b|gir-`Da z?o)LoK4@1}ortQgl%|fzhfz|AN|73=Kl$j#thEvpsS-c==%4cuscIFqch(qeK$SY$ zy>sW@J7><!?wrNY=RKAm%;qu#Ek5^bbji11(V6Izdf9I3JsD$3Jl|r*f`^c#yGtQ7 z4{yFjsGERL8as$)sWXGqOw3fMBJ(81jbugVbhDe|fB}X1Y@CzW3ru02L``b0Xp*?C z(J9BKS_3H-2RGH`qy3v|^SG6gK2@|+gyc(RqoKgn!BJ@DW66+W<zaKhM))FxzXd!_ z0|6sZ#pvWjfWt<%sFLJv0;3X+MLX8=aBk#8rj3LhS=w!ss3=`}$`mRPYuP?qgt~r? z{sLlaF~6d--MY#wHPgJl(*K!tJZ6*?-rGt~>d85Y&5}MsyNRnc80j`flR6R<y#;;- ztrq?lhn_+Jv|#q^jcgzpN{|fOBIQ4uQwM7j9Qh0Lfy3la7HKel`~$7NY(;-@Vk#z< zlW+x?6@xf@d2Cd)lK`PD_7dYDriU0pv%XBOv-H-8UEr@U?_Qa>9BW<c_pX?3oQ3hI zI5j#FlNW3i!VWTxn784b>ZawC#UFppAdCI0w%NF152*G)x>~U}D&{8D+>}F3L(el} z64dWD$80=xRdv=Ywg%PKkYLs#>DKSAsm^A_wnw$?Ni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RGg5<Dj`r}k+|TN%n}6_JF?FUcHGxe<1=QwClpYVMM2pKachnWLH+nQUsB`4^u{ z;8SHr*kMF7r+>_Oa@sMN%0(_EQt3!)Wc0HIDnA@jX!_QRFdd+FtBfPS$xe)?a@8VM z&H-oImCi&iWR!GL$wu~fTp+(SDFeTN!K(0Cv^4o`b`~i|U?j$@aTk;CKKL7Cx_;xT z*`$(7WzsRM3;_=w4Fw(zl9r<OLFg;5kk6$(ymAcMWJPK_qr5~%DcpiTTZ9WZi^@Ws zA%wr`GujT`Z)(@v_pwX6WZ;mALplzX>l!qnENv?uUFcqnE*-tmtq1mLE?VN-Du}D; zwSb%s9(n$r=+phr8DiWN<GL7sSoZiUh^+~H(N-8;=(^Um=q*W|y3~2k>7DN}oUNv_ zRd=?MrC^~ChV;6q;p{M-9lEol?34;A!x`01RvgIFTzGHsEvQ$sWp~NFTX*lSxRDqv z4C$VoI^J11PTmO>?5AjEL!_a3dx++Dqq=j-VQ4?X2QOvhsqtjLa)rFwd^5I-*<ajS jL7<jSTk7X2OKk<2bcB0*qD<E^*g@T`Dy#i0uny}VE(*@V diff --git a/server/map/get_relation.py b/server/map/get_relation.py index 4d32b06f..81f7ce5f 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -96,46 +96,42 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float): remaining_shape = [] # Loop through points and check which side of the division line they are - if cell_size > 0: # Horizontal split - for point in exterior_coords: - point = Point(point) # Convert coordinates to Shapely Point object - if point.y < divisor: # Check if point is over or below divisor - split_shape.append(point) # Append to appropriate shape + for i in range(len(exterior_coords) - 1): + point1 = Point(exterior_coords[i]) + point2 = Point(exterior_coords[i + 1]) + + # Check if both points are on the same side of the divisor + if (point1.y < divisor and point2.y < divisor) or (point1.y >= divisor and point2.y >= divisor): + # Both points on same side, add to appropriate shape + if point1.y < divisor: + split_shape.append(exterior_coords[i]) else: - remaining_shape.append(point) - - # 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] - - else: # Vertical split - for point in exterior_coords: - point = Point(point) # Convert coordinates to Shapely Point object - if point.x < divisor: - split_shape.append(point) + remaining_shape.append(exterior_coords[i]) + else: + # Points on different sides, calculate intersection with divisor + x_intersect = point1.x + (divisor - point1.y) * (point2.x - point1.x) / (point2.y - point1.y) + + # Add intersection point to both shapes + split_shape.append((x_intersect, divisor)) + remaining_shape.append((x_intersect, divisor)) + + # Determine which side each original point belongs to + if point1.y < divisor: + split_shape.append((point2.x, point2.y)) else: - remaining_shape.append(point) - - # Check if the split_shape has enough coordinates to create a polygon - if len(split_shape) < 3: - # print("Not enough coordinates to create valid polygon: Split shape: ", len(split_shape)) - split_shape = None - else: - split_shape.append(split_shape[0]) # Append first coord to create closed loop - - # Check if the remaining_shape has enough coordinates to create a polygon - if len(remaining_shape) < 3: - # print("Not enough coordinates to create valid polygon: Remaining shape: ", len(remaining_shape)) - remaining_shape = None - else: - remaining_shape.append(remaining_shape[0]) # Append first coord to create closed loop - - # Return split polygons as Shapely Polygon objects + remaining_shape.append((point2.x, point2.y)) + + # Ensure that the shapes are closed loops + if len(split_shape) > 0 and split_shape[0] != split_shape[-1]: + split_shape.append(split_shape[0]) + + if len(remaining_shape) > 0 and remaining_shape[0] != remaining_shape[-1]: + remaining_shape.append(remaining_shape[0]) + 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 @@ -178,20 +174,17 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f # Define starting point with an x-value that will be common for all polygons starting_point = polygon_min_x - print("Hit main if") # Create list of corners corners = [] - divisor_range = ((divisor - 0.1),(divisor + 0.1)) # Define tolerance + 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.y < divisor_range[1]: corners.append(point) - print("Hit point in split_shape") if not corners or len(corners) < 2: - print("no corners :(") return None # Sort corners in ascending order (left to right) based on x coordinate @@ -207,7 +200,6 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f while starting_point < sorted_corners[-1].x: 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 - print("Hit point insertion") starting_point += cell_size -- GitLab