Search in sources :

Example 81 with Polygon

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

the class MultiPolygonSegment method next.

@Override
public Segment next() {
    this.segmentIndex++;
    final Polygonal polygonal = this.polygonal;
    final int geometryCount = polygonal.getGeometryCount();
    while (this.partIndex < geometryCount) {
        final Polygon polygon = getPolygon();
        final int ringCount = polygon.getRingCount();
        while (this.ringIndex < ringCount) {
            final LinearRing ring = polygon.getRing(this.ringIndex);
            if (this.segmentIndex < ring.getSegmentCount()) {
                return this;
            } else {
                this.ringIndex++;
                this.segmentIndex = 0;
            }
        }
        this.partIndex++;
        this.ringIndex = 0;
        this.segmentIndex = 0;
    }
    throw new NoSuchElementException();
}
Also used : Polygonal(com.revolsys.geometry.model.Polygonal) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing) NoSuchElementException(java.util.NoSuchElementException)

Example 82 with Polygon

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

the class PolygonSegment method hasNext.

@Override
public boolean hasNext() {
    if (getGeometry().isEmpty()) {
        return false;
    } else {
        final Polygon polygon = this.polygon;
        int ringIndex = this.ringIndex;
        int segmentIndex = this.segmentIndex;
        while (ringIndex < polygon.getRingCount()) {
            final LinearRing ring = polygon.getRing(ringIndex);
            if (segmentIndex + 1 < ring.getSegmentCount()) {
                return true;
            } else {
                ringIndex++;
                segmentIndex = 0;
            }
        }
        return false;
    }
}
Also used : Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 83 with Polygon

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

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

the class ConnectedInteriorTester method visitShellInteriors.

/**
 * Mark all the edges for the edgeRings corresponding to the shells
 * of the input polygons.
 * Only ONE ring gets marked for each shell - if there are others which remain unmarked
 * this indicates a disconnected interior.
 */
private void visitShellInteriors(final Geometry g, final PlanarGraph graph) {
    if (g instanceof Polygon) {
        final Polygon p = (Polygon) g;
        visitInteriorRing(p.getShell(), graph);
    } else if (g instanceof Polygonal) {
        final Polygonal polygonal = (Polygonal) g;
        for (final Polygon polygon : polygonal.polygons()) {
            visitInteriorRing(polygon.getShell(), graph);
        }
    }
}
Also used : Polygonal(com.revolsys.geometry.model.Polygonal) Polygon(com.revolsys.geometry.model.Polygon)

Example 85 with Polygon

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

the class OsmPbfRecordIterator method isPolygon.

public boolean isPolygon(final OsmWay way, final Geometry geometry) {
    if (geometry instanceof LineString) {
        final LineString line = (LineString) geometry;
        if (line.isClosed()) {
            boolean isPolygon = true;
            if (!"yes".equals(way.getTag("area"))) {
                if (way.containsKey("barrier")) {
                    isPolygon = false;
                } else if (way.containsKey("highway")) {
                    isPolygon = false;
                }
            }
            if (isPolygon) {
                final Polygon polygon = line.getGeometryFactory().polygon(line);
                way.setGeometryValue(polygon);
            }
            return isPolygon;
        }
    }
    return false;
}
Also used : LineString(com.revolsys.geometry.model.LineString) Polygon(com.revolsys.geometry.model.Polygon)

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