Created
May 4, 2016 22:56
-
-
Save mhweber/c2fca3632eb37469208e7b68f0d668f6 to your computer and use it in GitHub Desktop.
A function using shapely geometries to check for any intersecting 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
import geopandas as gpd | |
from itertools import combinations | |
Feat1 = gpd.GeoDataFrame.from_file('Feat1.shp') | |
Feat2 = gpd.GeoDataFrame.from_file('Feat2.shp') | |
Feat3= gpd.GeoDataFrame.from_file('Feat3.shp') | |
# gather geometries in iterable a list | |
shapes = [Feat1, Feat2, Feat3] | |
# or to show catching overlap try | |
shapes = [Feat1, Feat2=1, Feat3] | |
def CheckPolyIntersections(PolygonList): | |
# test the intersection on the combinations of pairs | |
intersections = [pair[0].intersects(pair[1]) for pair in combinations(shapes, 2)] | |
if any(intersections[i][0]==True for i in range(0, len(intersections))): | |
print("yes, %d of %d combinations intersect" % (sum(intersections), len(intersections))) | |
else: | |
print("no intersections") | |
CheckPolyIntersections(shapes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment