3

I have defined two polygons and I can find whether they intersect or not. I need to find the intersection vertices if they intersect or not ?

How can I do that ?

p1 = Polygon([(0,0), (1,1), (1,0)])
p2 = Polygon([(0,1), (1,0), (1,1)])
print(p1.intersects(p2))

This gives whether the polygons intersect but how to find the intersection vertex. I tried the following but it gave an error:

print(p1.intersects(p2).coords)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'bool' object has no attribute 'coords'

1 Answer 1

3

intersects() method returns True or False (Boolean) in shapely. You have to use intersection() method.

p1 = Polygon([(0,0), (1,1), (1,0)])
p2 = Polygon([(0,1), (1,0), (1,1)])
print(p1.intersection(p2))

# OUTPUT
# POLYGON ((0.5 0.5, 1 1, 1 0, 0.5 0.5))

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.