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));
}
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);
}
}
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;
}
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()));
}
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");
}
Aggregations