Search code examples
pythonpolygonopenstreetmapareashapely

Create new shapely polygon by finding the overlapping area


I have two polygons the red one and yellow one obtained from osm map. I want to extract the overlapping area as a polygon.

pol.intersects(pol2)

shapely gives the coordinates of only the red line. but i want to get the whole overlapped area as polygon.

enter image description here


Solution

  • Which version of shapely are you using? To intersect to polygons in 1.6.4.post2 use the following code example:

    from shapely.geometry import Point
    a = Point(1, 1).buffer(1.5)
    b = Point(2, 1).buffer(1.5)
    

    This creates two circle polygons that look like

    enter image description here

    a.intersection(b)
    

    The result is a polygon and will look like

    enter image description here