Search in sources :

Example 1 with LinearRing

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

the class GeometryGraph method addGeometry.

public void addGeometry(Geometry geometry) {
    geometry = getGeometryFactory().geometry(geometry);
    final Map<String, Object> properties = new LinkedHashMap<>();
    final int geometryIndex = this.geometries.size();
    properties.put("geometryIndex", geometryIndex);
    this.geometries.add(geometry);
    for (int partIndex = 0; partIndex < geometry.getGeometryCount(); partIndex++) {
        properties.put("partIndex", partIndex);
        final Geometry part = geometry.getGeometry(partIndex);
        if (part instanceof Point) {
            final Point point = (Point) part;
            this.points.add(point);
        } else if (part instanceof LineString) {
            final LineString line = (LineString) part;
            final LineString points = line;
            properties.put("type", "LineString");
            addEdges(points, properties);
        } else if (part instanceof Polygon) {
            final Polygon polygon = (Polygon) part;
            int ringIndex = 0;
            for (final LinearRing ring : polygon.rings()) {
                properties.put("ringIndex", ringIndex++);
                if (ringIndex == 0) {
                    properties.put("type", "PolygonShell");
                } else {
                    properties.put("type", "PolygonHole");
                }
                addEdges(ring, properties);
            }
            properties.remove("ringIndex");
        }
    }
    this.boundingBox = this.boundingBox.expandToInclude(geometry);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineString(com.revolsys.geometry.model.LineString) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing) Point(com.revolsys.geometry.model.Point) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with LinearRing

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

the class EdgeRing method toPolygon.

public Polygon toPolygon(final GeometryFactory geometryFactory) {
    final List<LinearRing> rings = new ArrayList<>();
    rings.add(getLinearRing());
    for (int i = 0; i < this.holes.size(); i++) {
        final LinearRing ring = this.holes.get(i).getLinearRing();
        rings.add(ring);
    }
    final Polygon poly = geometryFactory.polygon(rings);
    return poly;
}
Also used : ArrayList(java.util.ArrayList) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Example 3 with LinearRing

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

the class GeometryGraph method addPolygon.

private void addPolygon(final Polygon p) {
    addPolygonRing(p.getShell(), Location.EXTERIOR, Location.INTERIOR);
    for (int i = 0; i < p.getHoleCount(); i++) {
        final LinearRing hole = p.getHole(i);
        // Holes are topologically labelled opposite to the shell, since
        // the interior of the polygon lies on their opposite side
        // (on the left, if the hole is oriented CW)
        addPolygonRing(hole, Location.INTERIOR, Location.EXTERIOR);
    }
}
Also used : LinearRing(com.revolsys.geometry.model.LinearRing) Point(com.revolsys.geometry.model.Point)

Example 4 with LinearRing

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

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

the class PolygonEditor method newGeometry.

@Override
public Polygon newGeometry() {
    final int ringCount = this.editors.size();
    final LinearRing[] rings = new LinearRing[ringCount];
    int ringIndex = 0;
    for (final LinearRingEditor editor : this.editors) {
        rings[ringIndex++] = editor.newGeometry();
    }
    final GeometryFactory geometryFactory = getGeometryFactory();
    if (this.polygon == null) {
        return geometryFactory.polygon(rings);
    } else {
        return this.polygon.newPolygon(geometryFactory, rings);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LinearRing(com.revolsys.geometry.model.LinearRing) 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