Skip to content
Snippets Groups Projects
Commit cebda2a9 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

update: attempt to get only intersetcing lines, plotting error

parent 967a8662
No related branches found
No related tags found
1 merge request!6Clhp map
No preview for this file type
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment