Search in sources :

Example 51 with Polygon

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

the class GmlGeometryReader method readMultiPolygon.

private Polygonal readMultiPolygon(final GeometryFactory geometryFactory) throws XMLStreamException {
    int axisCount = 2;
    final GeometryFactory factory = getGeometryFactory(geometryFactory);
    final List<Polygon> polygons = new ArrayList<>();
    final int depth = this.in.getDepth();
    while (this.in.skipToStartElements(depth, Gml.POLYGON)) {
        final Polygon polygon = readPolygon(factory);
        if (polygon != null) {
            axisCount = Math.max(axisCount, polygon.getAxisCount());
            polygons.add(polygon);
        }
    }
    return factory.convertAxisCount(axisCount).polygonal(polygons);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ArrayList(java.util.ArrayList) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Example 52 with Polygon

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

the class GmlGeometryReader method readPolygon.

private Polygon readPolygon(final GeometryFactory geometryFactory) throws XMLStreamException {
    int axisCount = 2;
    final GeometryFactory factory = getGeometryFactory(geometryFactory);
    final List<LinearRing> rings = new ArrayList<>();
    final int depth = this.in.getDepth();
    while (this.in.skipToStartElements(depth, Gml.OUTER_BOUNDARY_IS, Gml.INNER_BOUNDARY_IS)) {
        final LinearRing ring = readLinearRing(factory);
        if (ring != null) {
            axisCount = Math.max(axisCount, ring.getAxisCount());
            rings.add(ring);
        }
    }
    final Polygon polygon = factory.convertAxisCount(axisCount).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 53 with Polygon

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

the class XmlGeometryFieldType method writeValueText.

@Override
protected void writeValueText(final XmlWriter out, final Object value) {
    if (value instanceof Point) {
        final Point point = (Point) value;
        writePoint(out, point);
    } else if (value instanceof LineString) {
        final LineString line = (LineString) value;
        writeLineString(out, line);
    } else if (value instanceof Polygon) {
        final Polygon polygon = (Polygon) value;
        writePolygon(out, polygon);
    } else if (value instanceof Lineal) {
        final Lineal multiLine = (Lineal) value;
        writeMultiLineString(out, multiLine);
    }
}
Also used : Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon)

Example 54 with Polygon

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

the class ArcGisRestServerFeatureIterator method parseMultiPolygon.

public static Geometry parseMultiPolygon(final GeometryFactory geometryFactory, final MapEx properties) {
    final List<Polygon> polygons = new ArrayList<>();
    final List<LinearRing> rings = new ArrayList<>();
    final List<List<List<Number>>> paths = properties.getValue("rings", Collections.emptyList());
    for (final List<List<Number>> points : paths) {
        final LinearRing ring = geometryFactory.linearRing(points);
        if (ring.isClockwise()) {
            if (!rings.isEmpty()) {
                final Polygon polygon = geometryFactory.polygon(rings);
                polygons.add(polygon);
            }
            rings.clear();
        }
        rings.add(ring);
    }
    if (!rings.isEmpty()) {
        final Polygon polygon = geometryFactory.polygon(rings);
        polygons.add(polygon);
    }
    return geometryFactory.geometry(polygons);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 55 with Polygon

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

the class KmlWriterUtil method writeGeometry.

// Assumes geometry is wgs84
public static void writeGeometry(final Writer out, final Geometry geometry, final int axisCount) throws IOException {
    if (geometry != null) {
        final int numGeometries = geometry.getGeometryCount();
        if (numGeometries > 1) {
            out.write("<MultiGeometry>\n");
            for (int i = 0; i < numGeometries; i++) {
                writeGeometry(out, geometry.getGeometry(i), axisCount);
            }
            out.write("</MultiGeometry>\n");
        } else {
            if (geometry instanceof Point) {
                final Point point = (Point) geometry;
                writePoint(out, point);
            } else if (geometry instanceof LinearRing) {
                final LinearRing line = (LinearRing) geometry;
                writeLinearRing(out, line);
            } else if (geometry instanceof LineString) {
                final LineString line = (LineString) geometry;
                writeLineString(out, line);
            } else if (geometry instanceof Polygon) {
                final Polygon polygon = (Polygon) geometry;
                writePolygon(out, polygon);
            } else if (geometry.isGeometryCollection()) {
                writeMultiGeometry(out, geometry, axisCount);
            }
        }
    }
}
Also used : 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)

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