Search in sources :

Example 1 with GeometryFactory

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

the class ValueGeometry method getEnvelopeUnion.

/**
 * Get the union.
 *
 * @param r the other geometry
 * @return the union of this geometry envelope and another geometry envelope
 */
public Value getEnvelopeUnion(ValueGeometry r) {
    GeometryFactory gf = new GeometryFactory();
    Envelope mergedEnvelope = new Envelope(getGeometryNoCopy().getEnvelopeInternal());
    mergedEnvelope.expandToInclude(r.getGeometryNoCopy().getEnvelopeInternal());
    return get(gf.toGeometry(mergedEnvelope));
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Envelope(org.locationtech.jts.geom.Envelope)

Example 2 with GeometryFactory

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

the class ValueGeometry method get.

/**
 * Get or create a geometry value for the given geometry.
 *
 * @param s the WKT representation of the geometry
 * @param srid the srid of the object
 * @return the value
 */
public static ValueGeometry get(String s, int srid) {
    try {
        GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), srid);
        Geometry g = new WKTReader(geometryFactory).read(s);
        return get(g);
    } catch (ParseException ex) {
        throw DbException.convert(ex);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

Example 3 with GeometryFactory

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

the class TestSpatial method pointTable.

/**
 * This method is called via reflection from the database.
 *
 * @param x the x position of the point
 * @param y the y position of the point
 * @return a result set with this point
 */
public static ResultSet pointTable(double x, double y) {
    GeometryFactory factory = new GeometryFactory();
    SimpleResultSet rs = new SimpleResultSet();
    rs.addColumn("THE_GEOM", Types.JAVA_OBJECT, "GEOMETRY", 0, 0);
    rs.addRow(factory.createPoint(new Coordinate(x, y)));
    return rs;
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) SimpleResultSet(org.h2.tools.SimpleResultSet) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 4 with GeometryFactory

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

the class TestSpatial method testGeometryDataType.

private void testGeometryDataType() {
    GeometryFactory geometryFactory = new GeometryFactory();
    Geometry geometry = geometryFactory.createPoint(new Coordinate(0, 0));
    assertEquals(Value.GEOMETRY, DataType.getTypeFromClass(geometry.getClass()));
}
Also used : ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 5 with GeometryFactory

use of org.locationtech.jts.geom.GeometryFactory 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)

Aggregations

GeometryFactory (org.locationtech.jts.geom.GeometryFactory)26 Coordinate (org.locationtech.jts.geom.Coordinate)13 Geometry (org.locationtech.jts.geom.Geometry)9 Test (org.junit.Test)8 PrecisionModel (org.locationtech.jts.geom.PrecisionModel)6 LineString (org.locationtech.jts.geom.LineString)4 Point (org.locationtech.jts.geom.Point)4 Envelope (org.locationtech.jts.geom.Envelope)3 Polygon (org.locationtech.jts.geom.Polygon)3 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)3 XmlObject (org.apache.xmlbeans.XmlObject)2 SimpleResultSet (org.h2.tools.SimpleResultSet)2 ValueGeometry (org.h2.value.ValueGeometry)2 LinearRing (org.locationtech.jts.geom.LinearRing)2 ParseException (org.locationtech.jts.io.ParseException)2 WKTReader (org.locationtech.jts.io.WKTReader)2 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)2 PointValuePair (org.n52.shetland.ogc.om.PointValuePair)2 InvalidSridException (org.n52.shetland.ogc.om.features.samplingFeatures.InvalidSridException)2 JTSHelperForTesting.randomCoordinate (org.n52.shetland.util.JTSHelperForTesting.randomCoordinate)2