Search in sources :

Example 16 with LinearRing

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

the class Polygonizer method addLineString.

public void addLineString(LineString lineString) {
    if (lineString instanceof LinearRing) {
        lineString = ((LinearRing) lineString).newLineStringEmpty();
    }
    // unioning the linestring with the point makes any self intersections
    // explicit.
    final Geometry geometry = lineString.newValidGeometry();
    // Add result to polygonizer
    add(geometry);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 17 with LinearRing

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

the class PolygonBuilder method findEdgeRingContaining.

/**
 * Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any.
 * The innermost enclosing ring is the <i>smallest</i> enclosing ring.
 * The algorithm used depends on the fact that:
 * <br>
 *  ring A contains ring B iff envelope(ring A) contains envelope(ring B)
 * <br>
 * This routine is only safe to use if the chosen point of the hole
 * is known to be properly contained in a shell
 * (which is guaranteed to be the case if the hole does not touch its shell)
 *
 * @return containing EdgeRing, if there is one
 * or null if no containing EdgeRing is found
 */
private EdgeRing findEdgeRingContaining(final EdgeRing testEr, final List<EdgeRing> shellList) {
    final LinearRing testRing = testEr.getLinearRing();
    final BoundingBox testEnv = testRing.getBoundingBox();
    final double testX = testRing.getX(0);
    final double testY = testRing.getY(0);
    EdgeRing minShell = null;
    BoundingBox minEnv = null;
    for (final EdgeRing tryShell : shellList) {
        final LinearRing tryRing = tryShell.getLinearRing();
        final BoundingBox tryEnv = tryRing.getBoundingBox();
        if (minShell != null) {
            minEnv = minShell.getLinearRing().getBoundingBox();
        }
        boolean isContained = false;
        if (tryEnv.covers(testEnv) && tryRing.isPointInRing(testX, testY)) {
            isContained = true;
        }
        // ring
        if (isContained) {
            if (minShell == null || minEnv.covers(tryEnv)) {
                minShell = tryShell;
            }
        }
    }
    return minShell;
}
Also used : EdgeRing(com.revolsys.geometry.geomgraph.EdgeRing) BoundingBox(com.revolsys.geometry.model.BoundingBox) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 18 with LinearRing

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

the class OffsetCurveSetBuilder method addPolygon.

private void addPolygon(final Polygon p) {
    double offsetDistance = this.distance;
    int offsetSide = Position.LEFT;
    if (this.distance < 0.0) {
        offsetDistance = -this.distance;
        offsetSide = Position.RIGHT;
    }
    final LinearRing shell = p.getShell();
    final boolean shellClockwise = shell.isClockwise();
    final LinearRing shellCoord = shell.removeDuplicatePoints();
    if (this.distance < 0.0 && isErodedCompletely(shell, this.distance)) {
    // optimization - don't bother computing buffer
    // if the polygon would be completely eroded
    } else if (this.distance <= 0.0 && shellCoord.getVertexCount() < 3) {
    // don't attempt to buffer a polygon with too few distinct vertices
    } else {
        addPolygonRing(shellCoord, shellClockwise, offsetDistance, offsetSide, Location.EXTERIOR, Location.INTERIOR);
        for (int i = 0; i < p.getHoleCount(); i++) {
            final LinearRing hole = p.getHole(i);
            final boolean holeClockwise = hole.isClockwise();
            final LinearRing holeCoord = hole.removeDuplicatePoints();
            // if the hole would be completely covered
            if (!(this.distance > 0.0 && isErodedCompletely(hole, -this.distance))) {
                // Holes are topologically labeled opposite to the shell, since
                // the interior of the polygon lies on their opposite side
                // (on the left, if the hole is oriented CCW)
                final int opposite = Position.opposite(offsetSide);
                addPolygonRing(holeCoord, holeClockwise, offsetDistance, opposite, Location.INTERIOR, Location.EXTERIOR);
            }
        }
    }
}
Also used : LinearRing(com.revolsys.geometry.model.LinearRing) Point(com.revolsys.geometry.model.Point)

Example 19 with LinearRing

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

the class ShapefileGeometryHandler method newPolygonGeometryFromParts.

public Geometry newPolygonGeometryFromParts(final GeometryFactory geometryFactory, final List<double[]> parts, final int axisCount) {
    final List<Polygon> polygons = new ArrayList<>();
    final List<LinearRing> currentParts = new ArrayList<>();
    for (final double[] coordinates : parts) {
        final LinearRing ring = geometryFactory.linearRing(axisCount, coordinates);
        final boolean ringClockwise = ring.isClockwise();
        if (ringClockwise) {
            if (!currentParts.isEmpty()) {
                final Polygon polygon = geometryFactory.polygon(currentParts);
                polygons.add(polygon);
                currentParts.clear();
            }
        }
        currentParts.add(ring);
    }
    if (!currentParts.isEmpty()) {
        final Polygon polygon = geometryFactory.polygon(currentParts);
        polygons.add(polygon);
    }
    if (polygons.size() == 1) {
        return polygons.get(0);
    } else {
        return geometryFactory.polygonal(polygons);
    }
}
Also used : ArrayList(java.util.ArrayList) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 20 with LinearRing

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

the class GeometryTestUtil method polygon.

public static Polygon polygon(final GeometryFactory geometryFactory, final int ringCount, final double delta) {
    final int axisCount = geometryFactory.getAxisCount();
    final List<LinearRing> rings = new ArrayList<>();
    for (int ringIndex = 0; ringIndex < ringCount; ringIndex++) {
        final double[] coordinates = new double[axisCount * 5];
        final double offset = delta / 100 * ringIndex;
        final double size = delta - offset * 2;
        final double[] firstPoint = coordinates(geometryFactory, delta);
        final double x = Doubles.makePrecise(1000000, firstPoint[0] + offset);
        final double y = Doubles.makePrecise(1000000, firstPoint[1] + offset);
        for (int vertexIndex = 0; vertexIndex < 5; vertexIndex++) {
            final double[] point = coordinates(geometryFactory, delta);
            point[0] = x;
            point[1] = y;
            if (vertexIndex == 1) {
                point[1] += size;
            } else if (vertexIndex == 2) {
                point[0] += size;
                point[1] += size;
            } else if (vertexIndex == 3) {
                point[0] += size;
            }
            point[0] = Doubles.makePrecise(1000000, point[0]);
            point[1] = Doubles.makePrecise(1000000, point[1]);
            CoordinatesListUtil.setCoordinates(coordinates, axisCount, vertexIndex, point);
        }
        LinearRing ring = geometryFactory.linearRing(axisCount, coordinates);
        if (ringIndex > 0) {
            ring = ring.reverse();
        }
        rings.add(ring);
    }
    final Polygon polygon = geometryFactory.polygon(rings);
    return polygon;
}
Also used : ArrayList(java.util.ArrayList) 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