Search in sources :

Example 26 with LinearRing

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

the class OgrRecordWriter method toOgrGeometry.

protected org.gdal.ogr.Geometry toOgrGeometry(final Geometry geometry, final int geometryType, final int axisCount) {
    final org.gdal.ogr.Geometry ogrGeometry = new org.gdal.ogr.Geometry(geometryType);
    if (!geometry.isEmpty()) {
        switch(geometryType) {
            case 1:
            case 0x80000000 + 1:
                {
                    final Point point = (Point) geometry;
                    final double x = point.getX();
                    final double y = point.getY();
                    if (axisCount == 2) {
                        ogrGeometry.AddPoint(x, y);
                    } else {
                        final double z = point.getZ();
                        ogrGeometry.AddPoint(x, y, z);
                    }
                }
                break;
            case 2:
            case 0x80000000 + 2:
                final LineString line = (LineString) geometry;
                final int vertexCount = line.getVertexCount();
                for (int vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
                    final double x = line.getX(vertexIndex);
                    final double y = line.getY(vertexIndex);
                    if (axisCount == 2) {
                        ogrGeometry.AddPoint(x, y);
                    } else {
                        final double z = line.getZ(vertexIndex);
                        ogrGeometry.AddPoint(x, y, z);
                    }
                }
                break;
            case 3:
            case 0x80000000 + 3:
                for (final LinearRing ring : ((Polygon) geometry).rings()) {
                    final org.gdal.ogr.Geometry ogrRing = toOgrGeometry(ring, 101, axisCount);
                    ogrGeometry.AddGeometry(ogrRing);
                }
                break;
            case 4:
                addParts(ogrGeometry, geometry, 1, axisCount);
                break;
            case 0x80000000 + 4:
                addParts(ogrGeometry, geometry, 0x80000000 + 1, axisCount);
                break;
            case 5:
                addParts(ogrGeometry, geometry, 2, axisCount);
                break;
            case 0x80000000 + 5:
                addParts(ogrGeometry, geometry, 0x80000000 + 2, axisCount);
                break;
            case 6:
                addParts(ogrGeometry, geometry, 3, axisCount);
                break;
            case 0x80000000 + 6:
                addParts(ogrGeometry, geometry, 0x80000000 + 3, axisCount);
                break;
            // return this.geometryFactory.geometry(parts);
            case 101:
                for (final Vertex vertex : geometry.vertices()) {
                    final double x = vertex.getX();
                    final double y = vertex.getY();
                    if (axisCount == 2) {
                        ogrGeometry.AddPoint(x, y);
                    } else {
                        final double z = vertex.getZ();
                        ogrGeometry.AddPoint(x, y, z);
                    }
                }
                break;
            default:
                return null;
        }
    }
    if (axisCount == 2) {
        ogrGeometry.FlattenTo2D();
    }
    return ogrGeometry;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Vertex(com.revolsys.geometry.model.vertex.Vertex) LineString(com.revolsys.geometry.model.LineString) 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 27 with LinearRing

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

the class LineStringEditor method newPolygon.

public Polygon newPolygon() {
    final LinearRing ring = newLinearRing();
    final GeometryFactory geometryFactory = getGeometryFactory();
    return geometryFactory.polygon(ring);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 28 with LinearRing

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

the class IndexedNestedRingTester method isNonNested.

public boolean isNonNested() {
    buildIndex();
    for (int i = 0; i < this.rings.size(); i++) {
        final LinearRing innerRing = (LinearRing) this.rings.get(i);
        final List results = this.index.getItems(innerRing.getBoundingBox());
        // System.out.println(results.size());
        for (int j = 0; j < results.size(); j++) {
            final LinearRing searchRing = (LinearRing) results.get(j);
            if (innerRing == searchRing) {
                continue;
            }
            if (!innerRing.getBoundingBox().intersects(searchRing.getBoundingBox())) {
                continue;
            }
            final Point innerRingPt = IsValidOp.findPtNotNode(innerRing, searchRing, this.graph);
            /**
             * If no non-node pts can be found, this means
             * that the searchRing touches ALL of the innerRing vertices.
             * This indicates an invalid polygon, since either
             * the two holes Construct a new disconnected interior,
             * or they touch in an infinite number of points
             * (i.e. along a line segment).
             * Both of these cases are caught by other tests,
             * so it is safe to simply skip this situation here.
             */
            if (innerRingPt == null) {
                continue;
            }
            final boolean isInside = searchRing.isPointInRing(innerRingPt);
            if (isInside) {
                this.nestedPt = innerRingPt;
                return false;
            }
        }
    }
    return true;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) LinearRing(com.revolsys.geometry.model.LinearRing) Point(com.revolsys.geometry.model.Point)

Example 29 with LinearRing

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

the class IndexedNestedRingTester method buildIndex.

private void buildIndex() {
    this.index = new StrTree();
    for (int i = 0; i < this.rings.size(); i++) {
        final LinearRing ring = (LinearRing) this.rings.get(i);
        final BoundingBox env = ring.getBoundingBox();
        this.index.insertItem(env, ring);
    }
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) StrTree(com.revolsys.geometry.index.strtree.StrTree) LinearRing(com.revolsys.geometry.model.LinearRing) Point(com.revolsys.geometry.model.Point)

Example 30 with LinearRing

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

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