在对多边形进行分割等操作之后,我想验证它是否是一个矩形。
我试过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...
Run Code Online (Sandbox Code Playgroud)
但如果起点位于边缘的中间,则该方法不起作用。
>>> #poly2 is actually a rectangle
>>> poly2 = Polygon([(0, 1), (0, 3), (2, 3), (2, …Run Code Online (Sandbox Code Playgroud)