Search in sources :

Example 6 with Polygon

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

the class GeometryCollectionImpl method forEachPolygon.

@Override
public void forEachPolygon(final Consumer<Polygon> action) {
    if (this.geometries != null) {
        for (final Geometry geometry : this.geometries) {
            if (geometry instanceof Polygon) {
                final Polygon polygon = (Polygon) geometry;
                action.accept(polygon);
            } else if (geometry instanceof GeometryCollection) {
                geometry.forEachPolygon(action);
            }
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryCollection(com.revolsys.geometry.model.GeometryCollection) Polygon(com.revolsys.geometry.model.Polygon)

Example 7 with Polygon

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

the class PolygonSegment method next.

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

Example 8 with Polygon

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

the class PolygonEditor method getCurrentGeometry.

@Override
public Geometry getCurrentGeometry() {
    final GeometryFactory geometryFactory = getGeometryFactory();
    if (isEmpty()) {
        return geometryFactory.polygon();
    }
    final List<LinearRing> rings = new ArrayList<>();
    final List<Geometry> geometries = new ArrayList<>();
    boolean shell = true;
    for (final LinearRingEditor editor : this.editors) {
        final Geometry ringGeometry = editor.getCurrentGeometry();
        if (ringGeometry instanceof LinearRing) {
            final LinearRing ring = (LinearRing) ringGeometry;
            if (shell || !rings.isEmpty()) {
                rings.add(ring);
            } else {
                geometries.add(ringGeometry);
            }
        } else {
            geometries.add(ringGeometry);
        }
        shell = false;
    }
    if (!rings.isEmpty()) {
        final Polygon polygon = geometryFactory.polygon(rings);
        if (geometries.isEmpty()) {
            return polygon;
        } else {
            geometries.add(polygon);
        }
    }
    return geometryFactory.geometry(geometries);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ArrayList(java.util.ArrayList) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon)

Example 9 with Polygon

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

the class MultiPolygonVertex method next.

@Override
public Vertex next() {
    final Polygonal polygonal = getPolygonal();
    this.vertexIndex++;
    while (this.partIndex < polygonal.getGeometryCount()) {
        final Polygon polygon = polygonal.getPolygon(this.partIndex);
        while (this.ringIndex < polygon.getRingCount()) {
            final LinearRing ring = polygon.getRing(this.ringIndex);
            if (this.vertexIndex < ring.getVertexCount()) {
                return this;
            } else {
                this.ringIndex++;
                this.vertexIndex = 0;
            }
        }
        this.partIndex++;
        this.ringIndex = 0;
        this.vertexIndex = 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 10 with Polygon

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

the class MultiPolygonVertex method getCoordinate.

@Override
public double getCoordinate(final int axisIndex) {
    final Polygon polygon = getPolygon();
    final LinearRing ring = polygon.getRing(this.ringIndex);
    if (ring == null) {
        return java.lang.Double.NaN;
    } else {
        return ring.getCoordinate(this.vertexIndex, axisIndex);
    }
}
Also used : Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing)

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