diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index d3f0c0786e20b0ddc077d121d821cf744be96425..06e348b394c484b248876e4f45c90e083c3acc46 100644 Binary files a/server/map/__pycache__/get_relation.cpython-311.pyc and b/server/map/__pycache__/get_relation.cpython-311.pyc differ diff --git a/server/map/get_relation.py b/server/map/get_relation.py index 6d7fc7ede4d0cdbb513db99a18a7e4ee40bb97d3..424fae44c8ffe7fd0a249e54f05bc6d715308ee1 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 +