Search in sources :

Example 1 with Polygon

use of org.locationtech.jts.geom.Polygon in project h2database by h2database.

the class TestSpatial method testSpatialValues.

private void testSpatialValues() throws SQLException {
    deleteDb("spatial");
    Connection conn = getConnection(URL);
    Statement stat = conn.createStatement();
    stat.execute("create memory table test" + "(id int primary key, polygon geometry)");
    stat.execute("insert into test values(1, " + "'POLYGON ((1 1, 1 2, 2 2, 1 1))')");
    ResultSet rs = stat.executeQuery("select * from test");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertEquals("POLYGON ((1 1, 1 2, 2 2, 1 1))", rs.getString(2));
    GeometryFactory f = new GeometryFactory();
    Polygon polygon = f.createPolygon(new Coordinate[] { new Coordinate(1, 1), new Coordinate(1, 2), new Coordinate(2, 2), new Coordinate(1, 1) });
    assertTrue(polygon.equals(rs.getObject(2)));
    rs = stat.executeQuery("select * from test where polygon = " + "'POLYGON ((1 1, 1 2, 2 2, 1 1))'");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    stat.executeQuery("select * from test where polygon > " + "'POLYGON ((1 1, 1 2, 2 2, 1 1))'");
    stat.executeQuery("select * from test where polygon < " + "'POLYGON ((1 1, 1 2, 2 2, 1 1))'");
    stat.execute("drop table test");
    conn.close();
    deleteDb("spatial");
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) Statement(java.sql.Statement) Connection(java.sql.Connection) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet) Polygon(org.locationtech.jts.geom.Polygon)

Example 2 with Polygon

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

the class JTSHelperTest method shouldReverseMultiPolygon.

@Test
public void shouldReverseMultiPolygon() throws OwsExceptionReport {
    final GeometryFactory factory = getGeometryFactoryForSRID(4326);
    testReverse(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)) }) }));
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Polygon(org.locationtech.jts.geom.Polygon) Test(org.junit.Test)

Example 3 with Polygon

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

the class GeoJSONTest method randomPolygon.

private Polygon randomPolygon(int srid) {
    Polygon geometry = geometryFactory.createPolygon(randomLinearRing(srid), new LinearRing[] { randomLinearRing(srid), randomLinearRing(srid), randomLinearRing(srid) });
    geometry.setSRID(srid);
    return geometry;
}
Also used : Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Example 4 with Polygon

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

the class GeoJSONTest method testPolygonWithZCoordinate.

@Test
public void testPolygonWithZCoordinate() throws GeoJSONDecodingException, IOException {
    Polygon geometry = randomPolygon(EPSG_4326);
    geometry.apply(new RandomZCoordinateFilter());
    geometry.geometryChanged();
    readWriteTest(geometry);
}
Also used : Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Test(org.junit.Test)

Example 5 with Polygon

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

the class GeoJSONEncoder method encode.

protected ObjectNode encode(MultiPolygon geometry, int parentSrid) {
    Preconditions.checkNotNull(geometry);
    ObjectNode json = jsonFactory.objectNode();
    ArrayNode list = json.put(JSONConstants.TYPE, JSONConstants.MULTI_POLYGON).putArray(JSONConstants.COORDINATES);
    for (int i = 0; i < geometry.getNumGeometries(); ++i) {
        list.add(encodeCoordinates((Polygon) geometry.getGeometryN(i)));
    }
    encodeCRS(json, geometry, parentSrid);
    return json;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) 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

Polygon (org.locationtech.jts.geom.Polygon)56 LineString (org.locationtech.jts.geom.LineString)23 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)22 Point (org.locationtech.jts.geom.Point)22 Geometry (org.locationtech.jts.geom.Geometry)20 Coordinate (org.locationtech.jts.geom.Coordinate)16 MultiPoint (org.locationtech.jts.geom.MultiPoint)15 Test (org.junit.Test)13 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)11 LinearRing (org.locationtech.jts.geom.LinearRing)10 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)8 MultiLineString (org.locationtech.jts.geom.MultiLineString)8 ArrayList (java.util.ArrayList)7 Test (org.junit.jupiter.api.Test)6 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)5 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)5 WKTReader (org.locationtech.jts.io.WKTReader)5 AreaIndex (com.graphhopper.routing.util.AreaIndex)4 CustomArea (com.graphhopper.routing.util.CustomArea)3 GeometryCollection (org.locationtech.jts.geom.GeometryCollection)3