From cebda2a9446bfd9a999b85f12be075d0a2498895 Mon Sep 17 00:00:00 2001 From: Sara <sarasdj@stud.ntnu.no> Date: Thu, 14 Mar 2024 10:39:29 +0100 Subject: [PATCH] update: attempt to get only intersetcing lines, plotting error --- .../__pycache__/get_relation.cpython-311.pyc | Bin 4190 -> 4528 bytes server/map/get_relation.py | 23 +++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index d3f0c0786e20b0ddc077d121d821cf744be96425..06e348b394c484b248876e4f45c90e083c3acc46 100644 GIT binary patch delta 771 zcmZWl&rcIU6rS16Zp(JJ?H0O<rHEF3+9(Ey8mmM_y{H$ABsE&Gvz9fb#o1NCw1ESM z#t==N_~Y0UYV<(Tf53}34=pyqY}EAPeWMrS$=PkdM8BE$&3oT_dGltz^=-rhuVh&S z43!T*v>v$<*bVPj2G1T#Nf=<5lT!f<Q$dWh&}|O$t0<*lVHKpp*sFP%;$uoD?qEt6 zhSOkJtZbx3FKg#v_VXj{h6%Vx&%@^dQ+94?!wk~*a1ZU_0tZThscg#t6j4!F=Ky%i ztc?=4wp2@UnrA=C>4r(1-j<pv%-_=US~{x}oPMC2bLoXbZmCw|A45T66~-re!Mo2V z@+WP;h%R`~4SZE1&+b$s4Rx@o4mOmbrZQCKzpIJYGaFh%O*YkJ*<be8zId}dd_$+? zIJ{h&lSkpf%+4^ZGh*hx?J09!fGj9+MK}enpDuZdo+`ZyJL!@b7RU&Tpc_6E6;wh+ zjzW3YGFpf1b<Em;VC_tin+D_(i-$dysOL?M7+S_OENREr3waWD3V3pe9Tv(G9b4hQ z`Fu8Q>N(9IS6G_NFfw>XeGbTRM~k#+8362LuQ6Hyt?p<YskQ)=hz$gO+@&&V`GZd; zA5FeI+VIDl{<sZL$9OBccPpCMjI!TqL?@cjiSosk)Vn41Z%X~uTtgabN@I0t>{rVl ztD_h>!TJwJtd6W!SeVV@S%audu|o7+;3`jI%%?-a!vpSEZ-86w&iUJyoG;*eIqek5 zup;N5j7_>2yfGoKxa%_r*SB{o)U_hpz63l{&Dek)|I$r55E_Y%%COf4|C4*`9|JbT A&;S4c delta 448 zcmdm>d{2RIIWI340}u%A{FM5JYa*WnW6MN!XSZD5C|*W}6owSW9KI+%FwGyu52gj8 z1XCEJgi=^ih0~Z)SX)@4L{ivV7@|Z|*i)H-A{;;wu@uH&22IY1i{iOBfQB;z@#jmE zxfyjBt0!A9PGhNITEI5>A(Qarn~c0nC4!UhFltOb#v;JfQ?prvDV14>Ew!Q~H815B zOHO8SNfA3x`{wnmeT-~;KvwaU$<FMG92~4B9~gkd<Q#Ta^&1?**EysvaY)TIS<1D- z^rC{{6$QhK(neRLjV^K+U*Rym07jdyv!}B%YEHK2Rc7?voXl&$$fPMgSwtX1?UrC} zVo5<xeo0Pdl3qz>a&~IbEj9>UBn!0k77I{5V{)T_zT!%TB5R;XktLA$#bJ}1pHiBW zYFCs1<T3(r@x95{1mXgeE-;{=8w|V+V0eRpy8#SuFbG|Mp$7sY4ZI&Xv=|K+B!6H4 WQs_j?<V-;=J_b=nu@4{u>;eGyYkd9y diff --git a/server/map/get_relation.py b/server/map/get_relation.py index 6d7fc7ed..424fae44 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -2,9 +2,7 @@ import geopandas as gpd from shapely.geometry import Polygon, LineString from shapely.ops import linemerge, unary_union, polygonize import matplotlib.pyplot as plt -import matplotlib.ticker as ticker import random -import math import numpy as np polygon_min_x = None # The left most point of the entire polygon @@ -26,7 +24,9 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water lines.append(polygon.boundary) lines = unary_union(lines) lines = linemerge(lines) - divided_map.extend(list(polygonize(lines))) + lines = (list(polygonize(lines))) + + divided_map = combine_gird_with_poly(polygon, lines) tiles = gpd.GeoDataFrame(geometry=divided_map) @@ -95,3 +95,20 @@ def create_grid(poly: Polygon, cell_size): x += cell_size return grid_lines + + +def combine_gird_with_poly(polygon, grid): + # Create an empty list to store tiles intersecting the polygon + intersecting_tiles = [] + + # Iterate through each grid line + for line in grid: + # Check if the line intersects with the polygon + if line.intersects(polygon): + # If the line intersects, find the intersection points + intersection = line.intersection(polygon) + # Add each line to the list + intersecting_tiles.append(intersection) + + return intersecting_tiles + -- GitLab