コード例 #1
0
def refinePoly(positions, parentInitialAverage):
    gparentPoint = Point(parentInitialAverage)
    childPoly = Polygon(positions)
    isInside = childPoly.covers(gparentPoint)
    updated = []
    if isInside:
        updated = np.average([parentInitialAverage, getAverage(positions)], 0)
    else:
        updated = getClosestPointPoly(childPoly, gparentPoint)
    return updated
コード例 #2
0
ファイル: form.py プロジェクト: multiply-org/multiply-ui
 def _adjust_zoom_level(event):
     if event['name'] == 'bounds' and leaflet_map.zoom < 18:
         southwest, northeast = leaflet_map.bounds
         map_bounds = Polygon([(southwest[1], southwest[0]),
                               (southwest[1], northeast[0]),
                               (northeast[1], northeast[0]),
                               (northeast[1], southwest[0]),
                               (southwest[1], southwest[0])])
         if map_bounds.covers(geom):
             leaflet_map.zoom = leaflet_map.zoom + 1
         elif leaflet_map.zoom > 1:
             leaflet_map.zoom = leaflet_map.zoom - 1
             leaflet_map.unobserve(_adjust_zoom_level)
コード例 #3
0
def intersect_circles(shapes, radius=0.61):
    try:
        shapes = [shape.buffer(radius) for shape in shapes]
        listpoly = [a.intersection(b) for a, b in combinations(shapes, 2)
                    ]  # list of intersections
        rings = [LineString(list(pol.exterior.coords))
                 for pol in listpoly]  # list of rings

        union = unary_union(rings)

        result = [geom for geom in polygonize(union)
                  ]  # list all intersection geometries

        multi = cascaded_union(
            result)  # Create a single geometry out of all intersections
        try:
            hulls = list(multi.exterior.coords)
            ys, xs = [arr.tolist() for arr in multi.exterior.xy]
            xs = [a for a, b, c, d, e, f, g, h in grouper(xs, 8)]
            ys = [a for a, b, c, d, e, f, g, h in grouper(ys, 8)]
            centroid = [list(reversed(list(multi.centroid.coords)[0]))]
        except:
            hulls = []
            xs, ys = [], []
            centroid = []

            for poly in multi:
                poly = Polygon([
                    list(sorted([x, y]))
                    for x, y in list(poly.convex_hull.exterior.coords)
                ])
                within = any(poly.within(other) for other in hulls)
                covers = any(poly.covers(other) for other in hulls)
                disjoint = not (any(poly.intersects(other) for other in hulls))
                if within:
                    print(f"Skipping {poly}")

                elif disjoint:
                    hulls.append(poly.convex_hull)
                else:
                    for i, hull in enumerate(hulls):
                        if poly.covers(hull):
                            print(f"replacing hull {i}")
                            hulls[i] = poly.convex_hull
                        if poly.intersects(hull):
                            print(f"merging hull {i}")
                            hulls[i] = poly.convex_hull.union(hull).convex_hull
                print(
                    f"{poly} is disjoint: {disjoint}; is within: {within}; covers: {covers}"
                )

                _ys, _xs = [arr.tolist() for arr in poly.exterior.xy]
                _xs = [a for a, b, c, d, e, f, g, h in grouper(_xs, 8)]
                _ys = [a for a, b, c, d, e, f, g, h in grouper(_ys, 8)]
                xs.extend(_xs)
                xs.extend([_xs[0], None])
                ys.extend(_ys)
                ys.extend([_ys[0], None])

                centroid.append(list(reversed(list(poly.centroid.coords[0]))))
            hulls = [
                Polygon(
                    list([
                        list(sorted([x, y]))
                        for x, y in list(poly.convex_hull.exterior.coords)
                    ])) for poly in hulls
            ]
    except Exception as e:
        print(e.__class__.__name__, e)
    return hulls, centroid