Search in sources :

Example 1 with MCPointInRing

use of com.revolsys.geometry.algorithm.MCPointInRing 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)

Example 2 with MCPointInRing

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

the class MCPointInRingTest method runPtInRing.

@Override
protected void runPtInRing(final Location expectedLoc, final Point pt, final String wkt) throws Exception {
    // isPointInRing is not defined for pts on boundary
    if (expectedLoc == Location.BOUNDARY) {
        return;
    }
    final Geometry geom = this.geometryFactory.geometry(wkt);
    if (!(geom instanceof Polygon)) {
        return;
    }
    final LinearRing ring = ((Polygon) geom).getShell();
    final boolean expected = expectedLoc == Location.INTERIOR;
    final MCPointInRing pir = new MCPointInRing(ring);
    final boolean result = pir.isInside(pt);
    assertEquals(expected, result);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing) MCPointInRing(com.revolsys.geometry.algorithm.MCPointInRing)

Aggregations

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