Search in sources :

Example 1 with PointInRing

use of com.revolsys.geometry.algorithm.PointInRing in project com.revolsys.open by revolsys.

the class IsValidOp method checkHolesInShell.

/**
 * Tests that each hole is inside the polygon shell.
 * This routine assumes that the holes have previously been tested
 * to ensure that all vertices lie on the shell oon the same side of it
 * (i.e that the hole rings do not cross the shell ring).
 * In other words, this test is only correct if the ConsistentArea test is passed first.
 * Given this, a simple point-in-polygon test of a single point in the hole can be used,
 * provided the point is chosen such that it does not lie on the shell.
 *
 * @param polygon the polygon to be tested for hole inclusion
 * @param graph a GeometryGraph incorporating the polygon
 */
private boolean checkHolesInShell(final Polygon polygon, final GeometryGraph graph) {
    boolean valid = true;
    final LinearRing shell = polygon.getShell();
    final PointInRing pir = new MCPointInRing(shell);
    for (final LinearRing hole : polygon.holes()) {
        final Point holePt = findPtNotNode(hole, shell, graph);
        /**
         * If no non-node hole vertex can be found, the hole must
         * split the polygon into disconnected interiors.
         * This will be caught by a subsequent check.
         */
        if (holePt != null) {
            final boolean outside = !pir.isInside(holePt);
            if (outside) {
                valid = false;
                addError(new TopologyValidationError(TopologyValidationError.HOLE_OUTSIDE_SHELL, holePt));
                if (isErrorReturn()) {
                    return false;
                }
            }
        }
    }
    return valid;
}
Also used : MCPointInRing(com.revolsys.geometry.algorithm.MCPointInRing) PointInRing(com.revolsys.geometry.algorithm.PointInRing) Point(com.revolsys.geometry.model.Point) LinearRing(com.revolsys.geometry.model.LinearRing) MCPointInRing(com.revolsys.geometry.algorithm.MCPointInRing)

Aggregations

MCPointInRing (com.revolsys.geometry.algorithm.MCPointInRing)1 PointInRing (com.revolsys.geometry.algorithm.PointInRing)1 LinearRing (com.revolsys.geometry.model.LinearRing)1 Point (com.revolsys.geometry.model.Point)1