示例#1
0
def get_valid_polygon(poly):
    p = sh.asPolygon(poly)
    if p.is_valid:
        return p

# else:
#     return p.simplify(0.00001,preserve_topology=False)

    pb = p.buffer(1e-9)
    if p.area > 0:
        d_area = (p.area - pb.area) / p.area
        if abs(d_area) < 1e-5:
            return pb

    line_non_simple = sh.LineString(poly)
    mls = shapely.ops.unary_union(line_non_simple)
    polygons = list(shapely.ops.polygonize(mls))
    if len(polygons) > 1:
        polyf = sh.Polygon(polygons[0])
        for i in np.arange(1, len(polygons)):
            polyf = polyf.union(sh.Polygon(polygons[i]))
        return polyf
    elif polygons != []:
        return sh.Polygon(polygons[0])
    else:
        return sh.Polygon([])
示例#2
0
def point_inside(list_of_points):
    """Returns a point that is guaranteed to be inside the polygon, thanks to Shapely."""
    polygon = shapely.Polygon(list_of_points)
    return polygon.representative_point().coords
示例#3
0
 def generatePolygon(self, list):
     self.player_polygon = shapely.Polygon(list)