Search in sources :

Example 46 with Polygon

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

the class UnaryUnionOp method union.

/**
 * Computes the geometric union of a {@link Collection}
 * of {@link Geometry}s.
 *
 * If no input geometries were provided but a {@link GeometryFactory} was provided,
 * an empty {@link Geometry} is returned.
 *
 * @param geoms a collection of geometries
 * @param geometryFactory the geometry factory to use if the collection is empty
 * @return the union of the geometries,
 * or an empty GEOMETRYCOLLECTION
 */
public static Geometry union(final Collection<? extends Geometry> geometries, GeometryFactory geometryFactory) {
    final List<Point> points = new ArrayList<>();
    final List<LineString> lines = new ArrayList<>();
    final List<Polygon> polygons = new ArrayList<>();
    for (final Geometry geometry : geometries) {
        if (geometryFactory == null) {
            geometryFactory = geometry.getGeometryFactory();
        }
        points.addAll(geometry.getGeometries(Point.class));
        lines.addAll(geometry.getGeometries(LineString.class));
        polygons.addAll(geometry.getGeometries(Polygon.class));
    }
    return union(geometryFactory, points, lines, polygons);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon)

Example 47 with Polygon

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

the class GeometricShapeFactory method newEllipse.

/**
 * Creates an elliptical {@link Polygon}.
 * If the supplied envelope is square the
 * result will be a circle.
 *
 * @return an ellipse or circle
 */
public Polygon newEllipse() {
    final BoundingBox env = this.dim.getEnvelope();
    final double xRadius = env.getWidth() / 2.0;
    final double yRadius = env.getHeight() / 2.0;
    final double centreX = env.getMinX() + xRadius;
    final double centreY = env.getMinY() + yRadius;
    final double[] coordinates = new double[(this.vertexCount + 1) * 2];
    int coordinateIndex = 0;
    for (int i = 0; i < this.vertexCount; i++) {
        final double ang = i * (2 * Math.PI / this.vertexCount);
        final double x = xRadius * Math.cos(ang) + centreX;
        final double y = yRadius * Math.sin(ang) + centreY;
        coordinates[coordinateIndex++] = x;
        coordinates[coordinateIndex++] = y;
    }
    coordinates[coordinateIndex++] = 0;
    coordinates[coordinateIndex++] = 1;
    final Polygon poly = this.geomFact.polygon(2, coordinates);
    return poly;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Example 48 with Polygon

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

the class GeometryTestUtil method multiPolygon.

public static Polygonal multiPolygon(final GeometryFactory geometryFactory, final int axisCount, final int partCount, final int ringCount) {
    final Polygon[] polygons = new Polygon[partCount];
    for (int partIndex = 0; partIndex < partCount; partIndex++) {
        polygons[partIndex] = polygon(geometryFactory, axisCount, partIndex, ringCount);
    }
    final Polygonal multiPolygon = geometryFactory.polygonal(polygons);
    return multiPolygon;
}
Also used : Polygonal(com.revolsys.geometry.model.Polygonal) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Example 49 with Polygon

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

the class GeoJsonGeometryReader method readMultiPolygon.

private Geometry readMultiPolygon(final boolean cogo) {
    final List<Polygon> polygons = new ArrayList<>();
    List<List<LineString>> polygonRings = null;
    GeometryFactory factory = this.geometryFactory;
    do {
        final JsonParser parser = this.in;
        final String fieldName = parser.skipToNextAttribute();
        if (GeoJson.COORDINATES.equals(fieldName)) {
            polygonRings = readCoordinatesListListList(cogo);
        } else if (GeoJson.CRS.equals(fieldName)) {
            factory = readCoordinateSystem();
        }
    } while (this.in.getEvent() != EventType.endObject && this.in.getEvent() != EventType.endDocument);
    int axisCount = 2;
    if (polygonRings != null) {
        for (final List<LineString> rings : polygonRings) {
            for (final LineString points : rings) {
                axisCount = Math.max(axisCount, points.getAxisCount());
            }
            factory = factory.convertAxisCount(axisCount);
            final Polygon polygon = factory.polygon(rings);
            polygons.add(polygon);
        }
    }
    return factory.polygonal(polygons);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LineString(com.revolsys.geometry.model.LineString) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point) JsonParser(com.revolsys.record.io.format.json.JsonParser)

Example 50 with Polygon

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

the class GeoJsonRecordWriter method geometry.

private void geometry(final Geometry geometry) {
    this.out.startObject();
    if (geometry instanceof Point) {
        final Point point = (Point) geometry;
        point(point);
    } else if (geometry instanceof LineString) {
        final LineString line = (LineString) geometry;
        line(line);
    } else if (geometry instanceof Polygon) {
        final Polygon polygon = (Polygon) geometry;
        polygon(polygon);
    } else if (geometry instanceof Punctual) {
        final Punctual punctual = (Punctual) geometry;
        multiPoint(punctual);
    } else if (geometry instanceof Lineal) {
        final Lineal lineal = (Lineal) geometry;
        multiLineString(lineal);
    } else if (geometry instanceof Polygonal) {
        final Polygonal polygonal = (Polygonal) geometry;
        multiPolygon(polygonal);
    } else if (geometry.isGeometryCollection()) {
        geometryCollection(geometry);
    }
    this.out.endObject();
}
Also used : Punctual(com.revolsys.geometry.model.Punctual) Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) Polygonal(com.revolsys.geometry.model.Polygonal) Point(com.revolsys.geometry.model.Point) 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