【发布时间】:2020-06-19 10:01:43
【问题描述】:
在Polygon上进行分割等操作后,我想验证它是一个矩形。
我试过simplify,然后计算coords的数量是否为5...
>>> from shapely.geometry import Polygon
>>> from shapely.ops import split
>>>
>>> poly1 = Polygon([(0, 0), (0, 1), (0, 3), (2, 3), (2, 2), (2, 0), (0, 0)])
>>>
>>> poly_check=poly1.simplify(0)
>>> if len(poly_check.exterior.coords)==5:
>>> print 'Yes, it is a rectangle...'
>>> else:
>>> print 'No, it is not a rectangle...'
>>>
Yes, it is a rectangle...
但是如果起点在边的中间就不行了。
>>> #poly2 is actually a rectangle
>>> poly2 = Polygon([(0, 1), (0, 3), (2, 3), (2, 2), (2, 0), (0, 0), (0, 1)])
>>>
>>> poly_check=poly2.simplify(0)
>>> if len(poly_check.exterior.coords)==5:
>>> print 'Yes, it is a rectangle...'
>>> else:
>>> print 'No, it is not a rectangle...'
>>>
No, it is not a rectangle...
如何检查?
谢谢
【问题讨论】:
标签: python polygon rectangles shapely