1

So I have two polygons: (i) An outer polygon, and (ii) an inner Polygon representing the 'hole'. I'm trying to merge these two to give a single Polygon, with the hole.

For easy illustration, the outer Polygon looks like:

enter image description here

And the (ii) Hole looks like:

enter image description here

Both these Polygons are Shapely Polygons. To create a Polygon with the hole, I researched a lot through this exchange and although I found limited resources, I tried the following:

#x: Shapely Polygon Type - The outer Polygon
#y: Shapely Polygon Type - The 'hole'
w=geometry.Polygon(x, holes=[y])

I still seem to be getting the same issue, the hole is not represented. Any tips?

2
  • If they're already Polygon objects then try w = x.difference(y)
    – mikewatt
    Mar 31, 2022 at 0:34
  • 1
    @mikewatt thank you so much! This is exactly what I was looking for. If you can make it into a formal answer, I'll gladly accept it! Mar 31, 2022 at 1:36

1 Answer 1

0

If starting with two Polygon objects then you can use the object.difference() method:

with_hole = outer.difference(inner)

Your Answer

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

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