AttributeError:'tuple'对象没有属性'coords'

时间:2016-02-07 17:21:34

标签: shapely concave-hull

def alpha_shape(points,alpha):     “””     计算一组的alpha形状(凹壳)     分数。     @param积分:可转换容器积分。     @param alpha:影响的alpha值         边境的粘性。数字较小         不要像大数字那样落入内心。         太大了,你失去了一切!     “””     concave_hull = []

if len(points) < 4:
    # When you have a triangle, there is no sense
    # in computing an alpha shape.
    return geometry.MultiPoint(list(points)).convex_hull
def add_edge(edges, edge_points, coords, i, j):
    """
    Add a line between the i-th and j-th points,
    if not in the list already
    """
    if (i, j) in edges or (j, i) in edges:
            # already added
            return
    else :    
            edges.add((i, j) )
            edge_points.append(coords[ [i, j] ])

coords = np.array([point.coords[0] for point in points])
tri = Delaunay(coords)
edges = set()
edge_points = []
# loop over triangles:
# ia, ib, ic = indices of corner points of the
# triangle
for ia, ib, ic in tri.vertices:
    pa = coords[ia]
    pb = coords[ib]
    pc = coords[ic]
    # Lengths of sides of triangle
    a = math.sqrt((pa[0]-pb[0])**2 + (pa[1]-pb[1])**2)
    b = math.sqrt((pb[0]-pc[0])**2 + (pb[1]-pc[1])**2)
    c = math.sqrt((pc[0]-pa[0])**2 + (pc[1]-pa[1])**2)
    # Semiperimeter of triangle
    s = (a + b + c)/2.0
    # Area of triangle by Heron's formula
    area = math.sqrt(s*(s-a)*(s-b)*(s-c))
    circum_r = a*b*c/(4.0*area)
    # Here's the radius filter.
    #print circum_r
    if circum_r < 1.0/alpha:
        add_edge(edges, edge_points, coords, ia, ib)
        add_edge(edges, edge_points, coords, ib, ic)
        add_edge(edges, edge_points, coords, ic, ia)
m = geometry.MultiLineString(edge_points)
triangles = list(polygonize(m))
return cascaded_union(triangles), edge_points

concave_hull,edge_points = alpha_shape(points,alpha = 1.87)

0 个答案:

没有答案