Fix invalid polygon in Shapely

后端 未结 1 1454
礼貌的吻别
礼貌的吻别 2020-12-28 12:45

Shapely defines a Polygon as invalid if any of its segments intersect, including segments that are colinear. Many software packages will create a region or area with a \"cut

相关标签:
1条回答
  • 2020-12-28 13:31

    I found a solution that works for the specific case given:

    >>> pp2 = pp.buffer(0)
    >>> pp2.is_valid
    True
    >>> pp2.exterior.coords[:]
    [(0.0, 0.0), (0.0, 3.0), (3.0, 3.0), (3.0, 0.0), (2.0, 0.0), (0.0, 0.0)]
    >>> pp2.interiors[0].coords[:]
    [(2.0, 1.0), (2.0, 2.0), (1.0, 2.0), (1.0, 1.0), (2.0, 1.0)]
    
    0 讨论(0)
提交回复
热议问题