Beispiel #1
0
    def intersectIslands(self, paths,
                         islands: List[Island]) -> Tuple[Any, Any]:
        """
        Perform the intersection and overlap tests on the island sub regions. This should be performed before any
        clipping operations are performed.

        :param paths: List of coordinates describing the boundary
        :param islands: A list of Islands to have the intersection and overlap test

        :return: A tuple containing lists of clipped and unClipped islands
        """
        polys = []
        for path in paths:
            polys += pathsToClosedPolygons(path)

        poly = MultiPolygon(polys)

        intersectIslands = []
        overlapIslands = []

        intersectIslandsSet = set()
        overlapIslandsSet = set()

        for i in range(len(islands)):

            island = islands[i]
            s = island.boundary()

            if poly.overlaps(s):
                overlapIslandsSet.add(i)  # id
                overlapIslands.append(island.boundary)
                island.setRequiresClipping(True)

            if poly.intersects(s):
                intersectIslandsSet.add(i)  # id
                intersectIslands.append(island.boundary)
                island.setIntersecting(True)

        unTouchedIslandSet = intersectIslandsSet - overlapIslandsSet
        unTouchedIslands = [islands[i] for i in unTouchedIslandSet]

        return overlapIslandsSet, unTouchedIslandSet
    poly = MultiPolygon(poly)

    intersectIslands = []
    overlapIslands = []

    # Python sets are used to perform boolean operations on a set to identify unclipped islands
    intersectIslandsSet = set()
    overlapIslandsSet = set()

    # Iterate across all the islands
    for i in range(len(islands)):

        island = islands[i]
        s = island.boundary()

        if poly.overlaps(s):
            overlapIslandsSet.add(i)  # id
            overlapIslands.append(island)

        if poly.intersects(s):
            intersectIslandsSet.add(i)  # id
            intersectIslands.append(island)

    unTouchedIslandSet = intersectIslandsSet - overlapIslandsSet
    unTouchedIslands = [islands[i] for i in unTouchedIslandSet]

    print('Finished Island Clipping')

    fig, ax = pyslm.visualise.plotPolygon(geomSlice)

    # Plot using visualise.plotPolygon the original islands generated before intersection