8

I am trying to get the intersecting point coordinates of 2 polygons in Python.

For example intersecting points of the two polygons (polys2). For illustration purpose, I have marked the intersecting points in green.

from shapely.geometry import Polygon,Point
import geopandas
polys1 = geopandas.GeoSeries([Polygon([(0,0), (2,0), (2,2), (0,2)]),
                               Polygon([(1,1), (3,1), (3,3), (1,3)])])
 
polys2 = geopandas.GeoSeries([Point([(1,2)]),Point([(2,1)]) ])
                                  
df1 = geopandas.GeoDataFrame({'geometry': polys1, 'df1':[1,2]})
df2 = geopandas.GeoDataFrame({'geometry': polys2, 'df2':[1,2]})

ax = df1.plot(color='red', alpha = 0.5)
df2.plot(ax=ax, color='green', alpha=0.5);

enter image description here

What is the best way to find these intersecting points in Python?

1 Answer 1

11

Use intersection of polygons' boundary. In your case it returns intersecting points as multipoint.

geom1 = df1.geometry[0]
geom2 = df1.geometry[1]

points = geom1.boundary.intersection(geom2.boundary) # multipoint
points = list(points) # point list

print(points)
#[<shapely.geometry.point.Point at ...>,
# <shapely.geometry.point.Point at ...>]
1
  • 2
    Thanks a lot @Kadir Şahbaz . Just to complete the answer for future benefits: final coordinates of the intersecting points : points[0].wkt,points[1].wkt
    – Shana
    Commented Sep 14, 2020 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.