Search in sources :

Example 1 with EdgeRing

use of com.revolsys.geometry.geomgraph.EdgeRing in project com.revolsys.open by revolsys.

the class PolygonBuilder method buildMinimalEdgeRings.

private List<MaximalEdgeRing> buildMinimalEdgeRings(final List<MaximalEdgeRing> maxEdgeRings, final List<EdgeRing> shellList, final List<EdgeRing> freeHoleList) {
    final List<MaximalEdgeRing> edgeRings = new ArrayList<>();
    for (final MaximalEdgeRing er : maxEdgeRings) {
        if (er.getMaxNodeDegree() > 2) {
            er.linkDirectedEdgesForMinimalEdgeRings();
            final List<MinimalEdgeRing> minEdgeRings = er.buildMinimalRings();
            // at this point we can go ahead and attempt to place holes, if this
            // EdgeRing is a polygon
            final EdgeRing shell = findShell(minEdgeRings);
            if (shell != null) {
                placePolygonHoles(shell, minEdgeRings);
                shellList.add(shell);
            } else {
                freeHoleList.addAll(minEdgeRings);
            }
        } else {
            edgeRings.add(er);
        }
    }
    return edgeRings;
}
Also used : EdgeRing(com.revolsys.geometry.geomgraph.EdgeRing) ArrayList(java.util.ArrayList)

Example 2 with EdgeRing

use of com.revolsys.geometry.geomgraph.EdgeRing in project com.revolsys.open by revolsys.

the class PolygonBuilder method getPolygons.

public List<Polygon> getPolygons() {
    final List<Polygon> polygons = new ArrayList<>();
    for (final EdgeRing edgeRing : this.shellList) {
        final Polygon polygon = edgeRing.toPolygon(this.geometryFactory);
        polygons.add(polygon);
    }
    return polygons;
}
Also used : EdgeRing(com.revolsys.geometry.geomgraph.EdgeRing) ArrayList(java.util.ArrayList) Polygon(com.revolsys.geometry.model.Polygon)

Example 3 with EdgeRing

use of com.revolsys.geometry.geomgraph.EdgeRing in project com.revolsys.open by revolsys.

the class PolygonBuilder method findEdgeRingContaining.

/**
 * Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any.
 * The innermost enclosing ring is the <i>smallest</i> enclosing ring.
 * The algorithm used depends on the fact that:
 * <br>
 *  ring A contains ring B iff envelope(ring A) contains envelope(ring B)
 * <br>
 * This routine is only safe to use if the chosen point of the hole
 * is known to be properly contained in a shell
 * (which is guaranteed to be the case if the hole does not touch its shell)
 *
 * @return containing EdgeRing, if there is one
 * or null if no containing EdgeRing is found
 */
private EdgeRing findEdgeRingContaining(final EdgeRing testEr, final List<EdgeRing> shellList) {
    final LinearRing testRing = testEr.getLinearRing();
    final BoundingBox testEnv = testRing.getBoundingBox();
    final double testX = testRing.getX(0);
    final double testY = testRing.getY(0);
    EdgeRing minShell = null;
    BoundingBox minEnv = null;
    for (final EdgeRing tryShell : shellList) {
        final LinearRing tryRing = tryShell.getLinearRing();
        final BoundingBox tryEnv = tryRing.getBoundingBox();
        if (minShell != null) {
            minEnv = minShell.getLinearRing().getBoundingBox();
        }
        boolean isContained = false;
        if (tryEnv.covers(testEnv) && tryRing.isPointInRing(testX, testY)) {
            isContained = true;
        }
        // ring
        if (isContained) {
            if (minShell == null || minEnv.covers(tryEnv)) {
                minShell = tryShell;
            }
        }
    }
    return minShell;
}
Also used : EdgeRing(com.revolsys.geometry.geomgraph.EdgeRing) BoundingBox(com.revolsys.geometry.model.BoundingBox) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 4 with EdgeRing

use of com.revolsys.geometry.geomgraph.EdgeRing in project com.revolsys.open by revolsys.

the class ConnectedInteriorTester method hasUnvisitedShellEdge.

/**
 * Check if any shell ring has an unvisited edge.
 * A shell ring is a ring which is not a hole and which has the interior
 * of the parent area on the RHS.
 * (Note that there may be non-hole rings with the interior on the LHS,
 * since the interior of holes will also be polygonized into CW rings
 * by the linkAllDirectedEdges() step)
 *
 * @return true if there is an unvisited edge in a non-hole ring
 */
private boolean hasUnvisitedShellEdge(final List edgeRings) {
    for (int i = 0; i < edgeRings.size(); i++) {
        final EdgeRing er = (EdgeRing) edgeRings.get(i);
        // don't check hole rings
        if (er.isHole()) {
            continue;
        }
        final List edges = er.getEdges();
        DirectedEdge de = (DirectedEdge) edges.get(0);
        // (MD - this check may now be irrelevant)
        if (de.getLabel().getLocation(0, Position.RIGHT) != Location.INTERIOR) {
            continue;
        }
        /**
         * the edgeRing is CW ring which surrounds the INT of the area, so check all
         * edges have been visited.  If any are unvisited, this is a disconnected part of the interior
         */
        for (int j = 0; j < edges.size(); j++) {
            de = (DirectedEdge) edges.get(j);
            // Debug.print("visted? "); Debug.println(de);
            if (!de.isVisited()) {
                // Debug.print("not visited "); Debug.println(de);
                this.disconnectedRingcoord = de.getCoordinate();
                return true;
            }
        }
    }
    return false;
}
Also used : DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) EdgeRing(com.revolsys.geometry.geomgraph.EdgeRing) MaximalEdgeRing(com.revolsys.geometry.operation.overlay.MaximalEdgeRing) ArrayList(java.util.ArrayList) List(java.util.List) Point(com.revolsys.geometry.model.Point)

Example 5 with EdgeRing

use of com.revolsys.geometry.geomgraph.EdgeRing in project com.revolsys.open by revolsys.

the class PolygonBuilder method findShell.

/**
 * This method takes a list of MinimalEdgeRings derived from a MaximalEdgeRing,
 * and tests whether they form a Polygon.  This is the case if there is a single shell
 * in the list.  In this case the shell is returned.
 * The other possibility is that they are a series of connected holes, in which case
 * no shell is returned.
 *
 * @return the shell EdgeRing, if there is one
 * or null, if all the rings are holes
 */
private EdgeRing findShell(final List<MinimalEdgeRing> minEdgeRings) {
    int shellCount = 0;
    EdgeRing shell = null;
    for (final MinimalEdgeRing er : minEdgeRings) {
        if (!er.isHole()) {
            shell = er;
            shellCount++;
        }
    }
    Assert.isTrue(shellCount <= 1, "found two shells in MinimalEdgeRing list");
    return shell;
}
Also used : EdgeRing(com.revolsys.geometry.geomgraph.EdgeRing) Point(com.revolsys.geometry.model.Point)

Aggregations

EdgeRing (com.revolsys.geometry.geomgraph.EdgeRing)5 ArrayList (java.util.ArrayList)3 Point (com.revolsys.geometry.model.Point)2 DirectedEdge (com.revolsys.geometry.geomgraph.DirectedEdge)1 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 LinearRing (com.revolsys.geometry.model.LinearRing)1 Polygon (com.revolsys.geometry.model.Polygon)1 MaximalEdgeRing (com.revolsys.geometry.operation.overlay.MaximalEdgeRing)1 List (java.util.List)1