Search in sources :

Example 61 with LinearRing

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

the class SierpinskiCarpetBuilder method getGeometry.

@Override
public Geometry getGeometry() {
    final int level = recursionLevelForSize(this.numPts);
    final LineSegment baseLine = getSquareBaseLine();
    final Point origin = baseLine.getPoint(0);
    final List<LinearRing> rings = new ArrayList<>();
    final LinearRing shell = ((Polygon) getSquareExtent().toGeometry()).getShell();
    rings.add(shell);
    addHoles(level, origin.getX(), origin.getY(), getDiameter(), rings);
    return this.geometryFactory.polygon(shell);
}
Also used : ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 62 with LinearRing

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

the class GeometryTransformer method transformPolygon.

protected Geometry transformPolygon(final Polygon polygon, final Geometry parent) {
    boolean isAllValidLinearRings = true;
    final Geometry newShell = transformLinearRing(polygon.getShell(), polygon);
    if (newShell == null || !(newShell instanceof LinearRing) || newShell.isEmpty()) {
        isAllValidLinearRings = false;
    }
    final List<Geometry> components = new ArrayList<>();
    components.add(newShell);
    for (final LinearRing hole : polygon.holes()) {
        final Geometry newHole = transformLinearRing(hole, polygon);
        if (Property.hasValue(newHole)) {
            if (!(newHole instanceof LinearRing)) {
            } else {
                isAllValidLinearRings = false;
            }
            components.add(newHole);
        }
    }
    if (isAllValidLinearRings) {
        return this.factory.polygon(components);
    } else {
        return this.factory.buildGeometry(components);
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) ArrayList(java.util.ArrayList) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 63 with LinearRing

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

the class SineStarFactory method newSineStar.

/**
 * Generates the geometry for the sine star
 *
 * @return the geometry representing the sine star
 */
public Geometry newSineStar() {
    final BoundingBox env = this.dim.getEnvelope();
    final double radius = env.getWidth() / 2.0;
    double armRatio = this.armLengthRatio;
    if (armRatio < 0.0) {
        armRatio = 0.0;
    }
    if (armRatio > 1.0) {
        armRatio = 1.0;
    }
    final double armMaxLen = armRatio * radius;
    final double insideRadius = (1 - armRatio) * radius;
    final double centreX = env.getMinX() + radius;
    final double centreY = env.getMinY() + radius;
    final double[] coordinates = new double[(this.vertexCount + 1) * 2];
    int coordinateIndex = 0;
    for (int i = 0; i < this.vertexCount; i++) {
        // the fraction of the way thru the current arm - in [0,1]
        final double ptArcFrac = i / (double) this.vertexCount * this.numArms;
        final double armAngFrac = ptArcFrac - Math.floor(ptArcFrac);
        // the angle for the current arm - in [0,2Pi]
        // (each arm is a complete sine wave cycle)
        final double armAng = 2 * Math.PI * armAngFrac;
        // the current length of the arm
        final double armLenFrac = (Math.cos(armAng) + 1.0) / 2.0;
        // the current radius of the curve (core + arm)
        final double curveRadius = insideRadius + armMaxLen * armLenFrac;
        // the current angle of the curve
        final double ang = i * (2 * Math.PI / this.vertexCount);
        final double x = curveRadius * Math.cos(ang) + centreX;
        final double y = curveRadius * Math.sin(ang) + centreY;
        coordinates[coordinateIndex++] = this.geomFact.makeXyPrecise(x);
        coordinates[coordinateIndex++] = this.geomFact.makeXyPrecise(y);
    }
    final LinearRing ring = this.geomFact.linearRing(2, coordinates);
    final Polygon poly = this.geomFact.polygon(ring);
    return poly;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon)

Example 64 with LinearRing

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

use of com.revolsys.geometry.model.LinearRing 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)

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