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

update: polygonize MLS objects

parent ebd0b777
No related branches found
No related tags found
1 merge request!7Clhp map
No preview for this file type
import geopandas as gpd import geopandas as gpd
from shapely.geometry import Polygon, LineString from shapely.geometry import Polygon, LineString, MultiLineString
from shapely.ops import linemerge, unary_union, polygonize from shapely.ops import linemerge, unary_union, polygonize
import matplotlib.pyplot as plt
import random
import json import json
import os import os
...@@ -84,17 +82,17 @@ def create_grid(poly: Polygon, cell_size): ...@@ -84,17 +82,17 @@ def create_grid(poly: Polygon, cell_size):
def combine_grid_with_poly(polygon, grid): def combine_grid_with_poly(polygon, grid):
# Create an empty list to store tiles intersecting the polygon
intersecting_tiles = [] intersecting_tiles = []
# Iterate through each grid line
for line in grid: for line in grid:
# Check if the line intersects with the polygon
if line.intersects(polygon): if line.intersects(polygon):
# If the line intersects, find the intersection points
intersection = line.intersection(polygon) intersection = line.intersection(polygon)
# Add each line to the list # Check if intersection is a MultiLineString
intersecting_tiles.append(intersection) if isinstance(intersection, MultiLineString):
# Extend the intersecting tiles with the polygonized results
intersecting_tiles.extend(list(polygonize(intersection)))
else:
intersecting_tiles.append(intersection)
return intersecting_tiles 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