Search in sources :

Example 66 with LinearRing

use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.

the class GeometricShapeFactory method newSupercircle.

/**
 * Creates a supercircular {@link Polygon}
 * of a given positive power.
 *
 * @return a supercircle
 */
public Polygon newSupercircle(final double power) {
    final double recipPow = 1.0 / power;
    final double radius = this.dim.getMinSize() / 2;
    final Point centre = this.dim.getCentre();
    final double r4 = Math.pow(radius, power);
    final double y0 = radius;
    final double xyInt = Math.pow(r4 / 2, recipPow);
    final int nSegsInOct = this.vertexCount / 8;
    final int totPts = nSegsInOct * 8 + 1;
    final Point[] pts = new Point[totPts];
    final double xInc = xyInt / nSegsInOct;
    for (int i = 0; i <= nSegsInOct; i++) {
        double x = 0.0;
        double y = y0;
        if (i != 0) {
            x = xInc * i;
            final double x4 = Math.pow(x, power);
            y = Math.pow(r4 - x4, recipPow);
        }
        pts[i] = coordTrans(x, y, centre);
        pts[2 * nSegsInOct - i] = coordTrans(y, x, centre);
        pts[2 * nSegsInOct + i] = coordTrans(y, -x, centre);
        pts[4 * nSegsInOct - i] = coordTrans(x, -y, centre);
        pts[4 * nSegsInOct + i] = coordTrans(-x, -y, centre);
        pts[6 * nSegsInOct - i] = coordTrans(-y, -x, centre);
        pts[6 * nSegsInOct + i] = coordTrans(-y, x, centre);
        pts[8 * nSegsInOct - i] = coordTrans(-x, y, centre);
    }
    pts[pts.length - 1] = pts[0];
    final LinearRing ring = this.geomFact.linearRing(pts);
    final Polygon poly = this.geomFact.polygon(ring);
    return poly;
}
Also used : Point(com.revolsys.geometry.model.Point) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Example 67 with LinearRing

use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.

the class IsValidOp method checkShellsNotNested.

/**
 * Tests that no element polygon is wholly in the interior of another element polygon.
 * <p>
 * Preconditions:
 * <ul>
 * <li>shells do not partially overlap
 * <li>shells do not touch along an edge
 * <li>no duplicate rings exist
 * </ul>
 * This routine relies on the fact that while polygon shells may touch at one or
 * more vertices, they cannot touch at ALL vertices.
 */
private boolean checkShellsNotNested(final Polygonal polygonal, final GeometryGraph graph) {
    boolean valid = true;
    final List<Polygon> polygons = polygonal.getPolygons();
    final int polygonCount = polygons.size();
    for (int i = 0; i < polygonCount; i++) {
        final Polygon polygon1 = polygons.get(i);
        final LinearRing shell = polygon1.getShell();
        for (int j = 0; j < polygonCount; j++) {
            if (i != j) {
                final Polygon polygon2 = polygons.get(j);
                valid &= checkShellNotNested(shell, polygon2, graph);
                if (isErrorReturn()) {
                    return false;
                }
            }
        }
    }
    return valid;
}
Also used : Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing) Point(com.revolsys.geometry.model.Point)

Example 68 with LinearRing

use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.

the class IsValidOp method checkShellNotNested.

/**
 * Check if a shell is incorrectly nested within a polygon.  This is the case
 * if the shell is inside the polygon shell, but not inside a polygon hole.
 * (If the shell is inside a polygon hole, the nesting is valid.)
 * <p>
 * The algorithm used relies on the fact that the rings must be properly contained.
 * E.g. they cannot partially overlap (this has been previously checked by
 * <code>checkRelateConsistency</code> )
 */
private boolean checkShellNotNested(final LinearRing shell, final Polygon polygon, final GeometryGraph graph) {
    // test if shell is inside polygon shell
    final LinearRing polyShell = polygon.getShell();
    final Point shellPt = findPtNotNode(shell, polyShell, graph);
    // polygon
    if (shellPt == null) {
        return true;
    } else {
        final boolean insidePolyShell = polyShell.isPointInRing(shellPt);
        if (!insidePolyShell) {
            return true;
        }
        // if no holes, this is an error!
        if (polygon.getHoleCount() <= 0) {
            addError(new TopologyValidationError(TopologyValidationError.NESTED_SHELLS, shellPt));
            return false;
        }
        /**
         * Check if the shell is inside one of the holes.
         * This is the case if one of the calls to checkShellInsideHole
         * returns a null coordinate.
         * Otherwise, the shell is not properly contained in a hole, which is an error.
         */
        Point badNestedPt = null;
        for (int i = 0; i < polygon.getHoleCount(); i++) {
            final LinearRing hole = polygon.getHole(i);
            badNestedPt = checkShellInsideHole(shell, hole, graph);
            if (badNestedPt == null) {
                return true;
            }
        }
        addError(new TopologyValidationError(TopologyValidationError.NESTED_SHELLS, badNestedPt));
        return false;
    }
}
Also used : Point(com.revolsys.geometry.model.Point) LinearRing(com.revolsys.geometry.model.LinearRing) Point(com.revolsys.geometry.model.Point)

Example 69 with LinearRing

use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.

the class MultiPolygonVertex method hasNext.

@Override
public boolean hasNext() {
    if (getGeometry().isEmpty()) {
        return false;
    } else {
        final Polygonal polygonal = getPolygonal();
        int partIndex = this.partIndex;
        int ringIndex = this.ringIndex;
        int vertexIndex = this.vertexIndex + 1;
        while (partIndex < polygonal.getGeometryCount()) {
            final Polygon polygon = polygonal.getPolygon(partIndex);
            while (ringIndex < polygon.getRingCount()) {
                final LinearRing ring = polygon.getRing(ringIndex);
                if (vertexIndex < ring.getVertexCount()) {
                    return true;
                } else {
                    ringIndex++;
                    vertexIndex = 0;
                }
            }
            partIndex++;
            ringIndex = 0;
            vertexIndex = 0;
        }
        return false;
    }
}
Also used : Polygonal(com.revolsys.geometry.model.Polygonal) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 70 with LinearRing

use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.

the class MultiPolygonVertex method getLineCoordinateRelative.

@Override
public double getLineCoordinateRelative(final int vertexOffset, final int axisIndex) {
    if (isEmpty()) {
        return java.lang.Double.NaN;
    } else {
        final int vertexIndex = getVertexIndex();
        final LinearRing getLine = getRing();
        return getLine.getCoordinate(vertexIndex + vertexOffset, axisIndex);
    }
}
Also used : LinearRing(com.revolsys.geometry.model.LinearRing)

Aggregations

LinearRing (com.revolsys.geometry.model.LinearRing)95 Polygon (com.revolsys.geometry.model.Polygon)53 Point (com.revolsys.geometry.model.Point)44 ArrayList (java.util.ArrayList)21 LineString (com.revolsys.geometry.model.LineString)19 Geometry (com.revolsys.geometry.model.Geometry)14 Polygonal (com.revolsys.geometry.model.Polygonal)11 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)9 BoundingBox (com.revolsys.geometry.model.BoundingBox)8 Lineal (com.revolsys.geometry.model.Lineal)7 Punctual (com.revolsys.geometry.model.Punctual)6 List (java.util.List)4 NoSuchElementException (java.util.NoSuchElementException)4 IOException (java.io.IOException)3 MCPointInRing (com.revolsys.geometry.algorithm.MCPointInRing)2 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)2 Vertex (com.revolsys.geometry.model.vertex.Vertex)2 BigDecimal (java.math.BigDecimal)2 PointInRing (com.revolsys.geometry.algorithm.PointInRing)1 EdgeRing (com.revolsys.geometry.geomgraph.EdgeRing)1