Search in sources :

Example 1 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project arctic-sea by 52North.

the class GeoJSONDecoder method decodePolygonCoordinates.

protected Polygon decodePolygonCoordinates(JsonNode coordinates, GeometryFactory fac) throws GeoJSONDecodingException {
    if (!coordinates.isArray()) {
        throw new GeoJSONDecodingException(EXPECTED_ARRAY);
    }
    if (coordinates.size() < 1) {
        throw new GeoJSONDecodingException("missing polygon shell");
    }
    LinearRing shell = fac.createLinearRing(decodeCoordinates(coordinates.get(0)));
    LinearRing[] holes = new LinearRing[coordinates.size() - 1];
    for (int i = 1; i < coordinates.size(); ++i) {
        holes[i - 1] = fac.createLinearRing(decodeCoordinates(coordinates.get(i)));
    }
    return fac.createPolygon(shell, holes);
}
Also used : GeoJSONDecodingException(org.n52.svalbard.coding.json.GeoJSONDecodingException) LinearRing(org.locationtech.jts.geom.LinearRing) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 2 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project arctic-sea by 52North.

the class JTSHelperTest method shouldReverseGeometryCollection.

@Test
public void shouldReverseGeometryCollection() throws OwsExceptionReport {
    final GeometryFactory factory = getGeometryFactoryForSRID(4326);
    testReverse(factory.createGeometryCollection(new Geometry[] { factory.createMultiPolygon(new Polygon[] { factory.createPolygon(factory.createLinearRing(randomCoordinateRing(13)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(130)), factory.createLinearRing(randomCoordinateRing(4121)), factory.createLinearRing(randomCoordinateRing(12)) }), factory.createPolygon(factory.createLinearRing(randomCoordinateRing(8)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(1101)), factory.createLinearRing(randomCoordinateRing(413)), factory.createLinearRing(randomCoordinateRing(123)) }), factory.createPolygon(factory.createLinearRing(randomCoordinateRing(89)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(112)), factory.createLinearRing(randomCoordinateRing(4)), factory.createLinearRing(randomCoordinateRing(43)) }) }), factory.createMultiLineString(new LineString[] { factory.createLineString(randomCoordinateRing(21)), factory.createLineString(randomCoordinateRing(21)), factory.createLineString(randomCoordinateRing(15)) }), factory.createPolygon(factory.createLinearRing(randomCoordinateRing(10)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(10)), factory.createLinearRing(randomCoordinateRing(41)), factory.createLinearRing(randomCoordinateRing(13)) }), getGeometryFactoryForSRID(4326).createLineString(randomCoordinates(10)), getGeometryFactoryForSRID(4326).createLineString(randomCoordinates(10)) }));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) LinearRing(org.locationtech.jts.geom.LinearRing) Test(org.junit.Test)

Example 3 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project arctic-sea by 52North.

the class JTSHelperTest method shouldReversePolygon.

@Test
public void shouldReversePolygon() throws OwsExceptionReport {
    final GeometryFactory factory = getGeometryFactoryForSRID(4326);
    testReverse(factory.createPolygon(factory.createLinearRing(randomCoordinateRing(10)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(10)), factory.createLinearRing(randomCoordinateRing(41)), factory.createLinearRing(randomCoordinateRing(13)) }));
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) LinearRing(org.locationtech.jts.geom.LinearRing) Test(org.junit.Test)

Example 4 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project arctic-sea by 52North.

the class GeoJSONTest method randomLinearRing.

private LinearRing randomLinearRing(int srid) {
    Coordinate p = randomCoordinate();
    LinearRing geometry = geometryFactory.createLinearRing(new Coordinate[] { p, randomCoordinate(), randomCoordinate(), randomCoordinate(), p });
    geometry.setSRID(srid);
    return geometry;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 5 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project yyl_example by Relucent.

the class JtsGeometryExample1 method createCircle.

/**
 * create a Circle 创建一个圆,圆心(x,y) 半径RADIUS
 * @param x 圆心X坐标
 * @param y 圆心X坐标
 * @param RADIUS 半径
 * @return 圆
 */
public static Polygon createCircle(double x, double y, final double RADIUS) {
    // 圆上面的点个数
    final int SIDES = 32;
    Coordinate[] coords = new Coordinate[SIDES + 1];
    for (int i = 0; i < SIDES; i++) {
        double angle = ((double) i / (double) SIDES) * Math.PI * 2.0;
        double dx = Math.cos(angle) * RADIUS;
        double dy = Math.sin(angle) * RADIUS;
        coords[i] = new Coordinate((double) x + dx, (double) y + dy);
    }
    coords[SIDES] = coords[0];
    LinearRing ring = GEOMETRY_FACTORY.createLinearRing(coords);
    Polygon polygon = GEOMETRY_FACTORY.createPolygon(ring, null);
    return polygon;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Aggregations

LinearRing (org.locationtech.jts.geom.LinearRing)66 Coordinate (org.locationtech.jts.geom.Coordinate)39 Polygon (org.locationtech.jts.geom.Polygon)33 Test (org.junit.Test)27 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)23 LineString (org.locationtech.jts.geom.LineString)14 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)10 Geometry (org.locationtech.jts.geom.Geometry)10 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)8 Point (org.locationtech.jts.geom.Point)8 MultiPoint (org.locationtech.jts.geom.MultiPoint)7 ArrayList (java.util.ArrayList)6 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)6 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)6 Test (org.junit.jupiter.api.Test)4 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)3 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)3 CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)3 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)3 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)3