use of org.locationtech.jts.geom.Geometry in project h2database by h2database.
the class TestSpatial method testInPlaceUpdate.
/**
* If the user mutate the geometry of the object, the object cache must not
* be updated.
*/
private void testInPlaceUpdate() throws SQLException {
try (Connection conn = getConnection(URL)) {
ResultSet rs = conn.createStatement().executeQuery("SELECT 'POINT(1 1)'::geometry");
assertTrue(rs.next());
// Mutate the geometry
((Geometry) rs.getObject(1)).apply(new AffineTransformation(1, 0, 1, 1, 0, 1));
rs.close();
rs = conn.createStatement().executeQuery("SELECT 'POINT(1 1)'::geometry");
assertTrue(rs.next());
// Check if the geometry is the one requested
assertEquals(1, ((Point) rs.getObject(1)).getX());
assertEquals(1, ((Point) rs.getObject(1)).getY());
rs.close();
}
}
use of org.locationtech.jts.geom.Geometry in project h2database by h2database.
the class TestSpatial method testAggregateWithGeometry.
private void testAggregateWithGeometry() throws SQLException {
deleteDb("spatialIndex");
try (Connection conn = getConnection("spatialIndex")) {
Statement st = conn.createStatement();
st.execute("CREATE AGGREGATE TABLE_ENVELOPE FOR \"" + TableEnvelope.class.getName() + "\"");
st.execute("CREATE TABLE test(the_geom GEOMETRY)");
st.execute("INSERT INTO test VALUES ('POINT(1 1)'), (null), (null), ('POINT(10 5)')");
ResultSet rs = st.executeQuery("select TABLE_ENVELOPE(the_geom) from test");
assertEquals("geometry", rs.getMetaData().getColumnTypeName(1).toLowerCase());
assertTrue(rs.next());
assertTrue(rs.getObject(1) instanceof Geometry);
assertTrue(new Envelope(1, 10, 1, 5).equals(((Geometry) rs.getObject(1)).getEnvelopeInternal()));
assertFalse(rs.next());
}
deleteDb("spatialIndex");
}
use of org.locationtech.jts.geom.Geometry in project arctic-sea by 52North.
the class GeoJSONDecoder method decodeGeometryCollection.
protected GeometryCollection decodeGeometryCollection(JsonNode node, GeometryFactory fac) throws GeoJSONDecodingException {
final JsonNode geometries = node.path(JSONConstants.GEOMETRIES);
if (!geometries.isArray()) {
throw new GeoJSONDecodingException("expected 'geometries' array");
}
Geometry[] geoms = new Geometry[geometries.size()];
for (int i = 0; i < geometries.size(); ++i) {
geoms[i] = decodeGeometry(geometries.get(i), fac);
}
return fac.createGeometryCollection(geoms);
}
use of org.locationtech.jts.geom.Geometry in project arctic-sea by 52North.
the class MultiPointObservation method getEnvelope.
/**
* Get the envelope from {@link PointValuePair}s {@link List}
*
* @param pointValuePairs
* The {@link PointValuePair}s to get the envelope from
* @return The envelope of the {@link PointValuePair}s
*/
private Geometry getEnvelope(List<PointValuePair> pointValuePairs) {
Envelope envelope = new Envelope();
GeometryFactory factory = null;
int srid = 4326;
if (CollectionHelper.isNotEmpty(pointValuePairs)) {
for (PointValuePair pointValuePair : pointValuePairs) {
if (factory == null && pointValuePair.getPoint() != null) {
factory = pointValuePair.getPoint().getFactory();
}
if (pointValuePair.getPoint().getSRID() > 0) {
srid = pointValuePair.getPoint().getSRID();
}
envelope.expandToInclude(pointValuePair.getPoint().getEnvelopeInternal());
}
} else {
if (isSetSpatialFilteringProfileParameter()) {
Geometry geometry = getSpatialFilteringProfileParameter().getValue().getValue();
if (geometry != null) {
if (factory == null) {
factory = geometry.getFactory();
}
if (geometry.getSRID() > 0) {
srid = geometry.getSRID();
}
envelope.expandToInclude(geometry.getEnvelopeInternal());
}
} else {
if (getObservationConstellation().getFeatureOfInterest() instanceof AbstractSamplingFeature && ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).isSetGeometry()) {
Geometry geometry = ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).getGeometry();
if (geometry != null) {
if (factory == null) {
factory = geometry.getFactory();
}
if (geometry.getSRID() > 0) {
srid = geometry.getSRID();
}
envelope.expandToInclude(geometry.getEnvelopeInternal());
}
}
}
}
if (factory == null) {
factory = JTSHelper.getGeometryFactoryForSRID(srid);
}
Geometry geometry = factory.toGeometry(envelope);
geometry.setSRID(srid);
return geometry;
}
use of org.locationtech.jts.geom.Geometry in project arctic-sea by 52North.
the class MultiPointObservation method getPoint.
/**
* Get the point from samplingGeometry or featureOfInterest
*
* @return The {@link Point}
*/
private Point getPoint() {
Point point = null;
if (isSetSpatialFilteringProfileParameter()) {
Geometry geometry = getSpatialFilteringProfileParameter().getValue().getValue();
point = geometry.getInteriorPoint();
point.setSRID(geometry.getSRID());
} else {
if (getObservationConstellation().getFeatureOfInterest() instanceof AbstractSamplingFeature && ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).isSetGeometry()) {
Geometry geometry = ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).getGeometry();
point = geometry.getInteriorPoint();
point.setSRID(geometry.getSRID());
}
}
return point;
}
Aggregations