Search in sources :

Example 56 with LinearRing

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

the class EdgeRing method containsPoint.

/**
 * This method will cause the ring to be computed.
 * It will also check any holes, if they have been assigned.
 */
public boolean containsPoint(final Point p) {
    final LinearRing shell = getLinearRing();
    final BoundingBox env = shell.getBoundingBox();
    if (!env.covers(p)) {
        return false;
    }
    if (!shell.isPointInRing(p)) {
        return false;
    }
    for (final EdgeRing hole : this.holes) {
        if (hole.containsPoint(p)) {
            return false;
        }
    }
    return true;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 57 with LinearRing

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

the class GeometryGraph method computeSelfNodes.

/**
 * Compute self-nodes, taking advantage of the Geometry type to
 * minimize the number of intersection tests.  (E.g. rings are
 * not tested for self-intersection, since they are assumed to be valid).
 * @param li the LineIntersector to use
 * @param computeRingSelfNodes if <false>, intersection checks are optimized to not test rings for self-intersection
 * @return the SegmentIntersector used, containing information about the intersections found
 */
public SegmentIntersector computeSelfNodes(final LineIntersector li, final boolean computeRingSelfNodes) {
    final SegmentIntersector si = new SegmentIntersector(li, true, false);
    final EdgeSetIntersector esi = newEdgeSetIntersector();
    // optimized test for Polygons and Rings
    if (!computeRingSelfNodes && (this.geometry instanceof LinearRing || this.geometry instanceof Polygonal)) {
        esi.computeIntersections(this.edges, si, false);
    } else {
        esi.computeIntersections(this.edges, si, true);
    }
    // System.out.println("SegmentIntersector # tests = " + si.numTests);
    addSelfIntersectionNodes(this.argIndex);
    return si;
}
Also used : Polygonal(com.revolsys.geometry.model.Polygonal) SegmentIntersector(com.revolsys.geometry.geomgraph.index.SegmentIntersector) EdgeSetIntersector(com.revolsys.geometry.geomgraph.index.EdgeSetIntersector) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 58 with LinearRing

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

the class Densifier method densify.

private static Polygon densify(final Polygon polygon, final double distanceTolerance) {
    // Attempt to fix invalid geometries
    final GeometryFactory geometryFactory = polygon.getGeometryFactory();
    final List<LinearRing> rings = new ArrayList<>();
    for (final LinearRing ring : polygon.rings()) {
        final LinearRing newRing = densify(ring, distanceTolerance);
        rings.add(newRing);
    }
    final Polygon newPolygon = geometryFactory.polygon(rings);
    return (Polygon) newPolygon.buffer(0);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ArrayList(java.util.ArrayList) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon)

Example 59 with LinearRing

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

the class KmlGeometryReader method parsePolygon.

private Polygon parsePolygon() throws XMLStreamException {
    this.in.requireLocalName(POLYGON);
    final List<LinearRing> rings = new ArrayList<>();
    int axisCount = 2;
    final int depth = this.in.getDepth();
    while (this.in.skipToStartElements(depth, OUTER_BOUNDARY_IS, INNER_BOUNDARY_IS)) {
        final LinearRing ring = parseRing();
        if (ring != null) {
            axisCount = Math.max(axisCount, ring.getAxisCount());
            rings.add(ring);
        }
    }
    final GeometryFactory geometryFactory = this.geometryFactory.convertAxisCount(axisCount);
    final Polygon polygon = geometryFactory.polygon(rings);
    return polygon;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ArrayList(java.util.ArrayList) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Example 60 with LinearRing

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

the class MeasureOverlay method deleteVertex.

private Geometry deleteVertex() {
    final Geometry geometry = getMeasureGeometry();
    for (final CloseLocation location : getMouseOverLocations()) {
        final int[] vertexId = location.getVertexId();
        if (vertexId != null) {
            if (geometry instanceof Point) {
                return null;
            } else if (geometry instanceof LineString) {
                final LineString line = (LineString) geometry;
                if (line.getVertexCount() == 2) {
                    if (vertexId.length == 1) {
                        if (vertexId[0] == 0) {
                            return line.getPoint(1);
                        } else {
                            return line.getPoint(0);
                        }
                    }
                }
            } else if (geometry instanceof Polygon) {
                final Polygon polygon = (Polygon) geometry;
                final LinearRing ring = polygon.getRing(0);
                if (ring.getVertexCount() == 4) {
                    if (vertexId.length == 2) {
                        final GeometryFactory geometryFactory = geometry.getGeometryFactory();
                        final Vertex point0 = ring.getVertex(0);
                        final Vertex point1 = ring.getVertex(1);
                        final Vertex point2 = ring.getVertex(2);
                        switch(vertexId[1]) {
                            case 0:
                                return geometryFactory.lineString(point1, point2);
                            case 1:
                                return geometryFactory.lineString(point2, point0);
                            default:
                                return geometryFactory.lineString(point0, point1);
                        }
                    }
                }
            }
            try {
                final GeometryEditor geometryEditor = geometry.newGeometryEditor();
                geometryEditor.deleteVertex(vertexId);
                if (geometryEditor.isModified()) {
                    return geometryEditor.newGeometry();
                }
            } catch (final Exception e) {
                Toolkit.getDefaultToolkit().beep();
                return geometry;
            }
        }
    }
    return geometry;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Vertex(com.revolsys.geometry.model.vertex.Vertex) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing) GeometryEditor(com.revolsys.geometry.model.editor.GeometryEditor)

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