AttributeError: ‘MultiPolygon‘ object has no attribute ‘exterior‘

使用shapely库爆出的错误。

看poly的类型,类型不一样,解决方案也不一样

if (poly.geom_type == 'MultiPolygon'):
            # if MultiPolygon, take the smallest convex Polygon containing all the points in the object
            poly = poly.convex_hull

if (poly.geom_type == 'Polygon'): # Ignore if still not a Polygon (could be a line or point)
            polygons.append(poly)
            segmentation = np.array(poly.exterior.coords).ravel().tolist()
            segmentations.append(segmentation)
posted @ 2023-02-06 17:30  赫凯  阅读(240)  评论(0编辑  收藏  举报