Search in sources :

Example 96 with Polygon

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

the class GeometricShapeFactory method newRectangle.

/**
 * Creates a rectangular {@link Polygon}.
 *
 * @return a rectangular Polygon
 */
public Polygon newRectangle() {
    int i;
    int ipt = 0;
    int nSide = this.vertexCount / 4;
    if (nSide < 1) {
        nSide = 1;
    }
    final double XsegLen = this.dim.getEnvelope().getWidth() / nSide;
    final double YsegLen = this.dim.getEnvelope().getHeight() / nSide;
    final Point[] pts = new Point[4 * nSide + 1];
    final BoundingBox env = this.dim.getEnvelope();
    for (i = 0; i < nSide; i++) {
        final double x = env.getMinX() + i * XsegLen;
        final double y = env.getMinY();
        pts[ipt++] = newPoint(x, y);
    }
    for (i = 0; i < nSide; i++) {
        final double x = env.getMaxX();
        final double y = env.getMinY() + i * YsegLen;
        pts[ipt++] = newPoint(x, y);
    }
    for (i = 0; i < nSide; i++) {
        final double x = env.getMaxX() - i * XsegLen;
        final double y = env.getMaxY();
        pts[ipt++] = newPoint(x, y);
    }
    for (i = 0; i < nSide; i++) {
        final double x = env.getMinX();
        final double y = env.getMaxY() - i * YsegLen;
        pts[ipt++] = newPoint(x, y);
    }
    pts[ipt++] = pts[0];
    final LinearRing ring = this.geomFact.linearRing(pts);
    final Polygon poly = this.geomFact.polygon(ring);
    return poly;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) 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 97 with Polygon

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

the class GeometricShapeFactory method newArcPolygon.

/**
 * Creates an elliptical arc polygon.
 * The polygon is formed from the specified arc of an ellipse
 * and the two radii connecting the endpoints to the centre of the ellipse.
 *
 * @param startAng start angle in radians
 * @param angExtent size of angle in radians
 * @return an elliptical arc polygon
 */
public Polygon newArcPolygon(final double startAng, final double angExtent) {
    final BoundingBox env = this.dim.getEnvelope();
    final double xRadius = env.getWidth() / 2.0;
    final double yRadius = env.getHeight() / 2.0;
    final double centreX = env.getMinX() + xRadius;
    final double centreY = env.getMinY() + yRadius;
    double angSize = angExtent;
    if (angSize <= 0.0 || angSize > 2 * Math.PI) {
        angSize = 2 * Math.PI;
    }
    final double angInc = angSize / (this.vertexCount - 1);
    // double check = angInc * nPts;
    // double checkEndAng = startAng + check;
    final Point[] pts = new Point[this.vertexCount + 2];
    int iPt = 0;
    pts[iPt++] = newPoint(centreX, centreY);
    for (int i = 0; i < this.vertexCount; i++) {
        final double ang = startAng + angInc * i;
        final double x = xRadius * Math.cos(ang) + centreX;
        final double y = yRadius * Math.sin(ang) + centreY;
        pts[iPt++] = newPoint(x, y);
    }
    pts[iPt++] = newPoint(centreX, centreY);
    final LinearRing ring = this.geomFact.linearRing(pts);
    final Polygon poly = this.geomFact.polygon(ring);
    return poly;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) 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 98 with Polygon

use of com.revolsys.geometry.model.Polygon 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 99 with Polygon

use of com.revolsys.geometry.model.Polygon 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 100 with Polygon

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

the class IsValidOp method checkValidMultiPolygon.

private boolean checkValidMultiPolygon(final Polygonal polygonal) {
    boolean valid = true;
    for (final Polygon polygon : polygonal.polygons()) {
        valid &= checkClosedRings(polygon);
        if (isErrorReturn()) {
            return false;
        }
    }
    final GeometryGraph graph = new GeometryGraph(0, polygonal);
    valid &= checkTooFewPoints(graph);
    if (isErrorReturn()) {
        return false;
    }
    valid &= checkConsistentArea(graph);
    if (isErrorReturn()) {
        return false;
    }
    if (!this.isSelfTouchingRingFormingHoleValid) {
        valid &= checkNoSelfIntersectingRings(graph);
        if (isErrorReturn()) {
            return false;
        }
    }
    for (final Polygon polygon : polygonal.getPolygons()) {
        valid &= checkHolesInShell(polygon, graph);
        if (isErrorReturn()) {
            return false;
        }
    }
    for (final Polygon polygon : polygonal.getPolygons()) {
        valid &= checkHolesNotNested(polygon, graph);
        if (isErrorReturn()) {
            return false;
        }
    }
    valid &= checkShellsNotNested(polygonal, graph);
    if (isErrorReturn()) {
        return false;
    }
    valid &= checkConnectedInteriors(graph);
    return valid;
}
Also used : Polygon(com.revolsys.geometry.model.Polygon) GeometryGraph(com.revolsys.geometry.geomgraph.GeometryGraph)

Aggregations

Polygon (com.revolsys.geometry.model.Polygon)147 Point (com.revolsys.geometry.model.Point)66 LinearRing (com.revolsys.geometry.model.LinearRing)54 LineString (com.revolsys.geometry.model.LineString)39 Geometry (com.revolsys.geometry.model.Geometry)34 ArrayList (java.util.ArrayList)30 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)22 Polygonal (com.revolsys.geometry.model.Polygonal)17 BoundingBox (com.revolsys.geometry.model.BoundingBox)14 Punctual (com.revolsys.geometry.model.Punctual)12 Test (org.junit.Test)12 Lineal (com.revolsys.geometry.model.Lineal)11 BaseCloseable (com.revolsys.io.BaseCloseable)7 List (java.util.List)7 PolygonEditor (com.revolsys.geometry.model.editor.PolygonEditor)6 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)6 Vertex (com.revolsys.geometry.model.vertex.Vertex)6 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)3 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)3 Graphics2D (java.awt.Graphics2D)3