3

I have two Polygons which intersect along one edge as shown below.

enter image description here

I need to add the red vertices at each end of the intersection to the blue polygon. I thought I could do this with by calling union on the Polygon and the LineString produced by intersection of the two polygons but it appears not.

Is there a way of doing what I need to do?

2

You can use the properties of union (and unary_union) witch split all the lines at intersections (Planar graph)

enter image description here

# LinearRing of the polygons
ringgreen = LineString(list(polygreen.exterior.coords))
ringblue  = LineString(list(polyblue.exterior.coords))
# Union of the rings
union = ringgreen.union(ringblue)
# now polygonize the result
from shapely.ops import polygonize
result = [geom for geom in polygonize(union]

enter image description here

and

enter image description here

1
  • That's actually just a less-roundabout way of doing what I was already doing. Thanks to your post confirming what is supposed to happen, I've found that I was getting tripped up by the fact I was translating my polygons first, then trying to do the union step. That was then failing because of floating point errors. – Jamie Bull Apr 8 '16 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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