Last active
October 2, 2019 18:05
-
-
Save tkwant/5ab2025c3b41bd7603a0eca5af9080f4 to your computer and use it in GitHub Desktop.
transforms a list of polygons into a list of levels with the polygons.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from shapely.geometry import Point | |
from shapely.geometry.polygon import Polygon | |
def isPolygonInPolygon(poly1,poly2): | |
poly2 = Polygon(poly2) | |
for poi in poly1: | |
poi = Point(poi) | |
if(poly2.contains(poi)): | |
return True | |
def polygonTransformHierarchy(polygon_list): | |
polygon_list_hierarchy = [] | |
for polygon1 in polygon_list: | |
level = 0 | |
for polygon2 in polygon_list: | |
if(isPolygonInPolygon(polygon1, polygon2)): | |
level += 1 | |
if(level > len(polygon_list_hierarchy)-1): | |
dif = (level+1)- len(polygon_list_hierarchy) | |
for _ in range(dif): | |
polygon_list_hierarchy.append([]) | |
polygon_list_hierarchy[level].append(polygon1) | |
return polygon_list_hierarchy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment