use of org.locationtech.jts.geom.Envelope in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_ReferencedEnvelope.
@Test
public void should_encode_ReferencedEnvelope() throws EncodingException {
final int srid = 4326;
final double y1 = 7.0;
final double x1 = 51.0;
final double y2 = 8.0;
final double x2 = 52.0;
final String uom = "test-uom";
final String definition = "test-definition";
final SweEnvelope sweEnvelope = new SweEnvelope(new ReferencedEnvelope(new Envelope(x1, x2, y1, y2), srid), uom, true);
final String xAxisId = "x";
final String yAxisId = "y";
final String northing = "northing";
final String easting = "easting";
sweEnvelope.setDefinition(definition);
final XmlObject encode = sweCommonEncoderv101.encode(sweEnvelope);
assertThat(encode, instanceOf(EnvelopeType.class));
final EnvelopeType xbEnvelope = (EnvelopeType) encode;
assertThat(xbEnvelope.isSetDefinition(), is(true));
assertThat(xbEnvelope.getDefinition(), is(definition));
final Coordinate lcX = xbEnvelope.getLowerCorner().getVector().getCoordinateArray(0);
assertThat(lcX.getName(), is(easting));
assertThat(lcX.getQuantity().getAxisID(), is(xAxisId));
assertThat(lcX.getQuantity().getUom().getCode(), is(uom));
assertThat(lcX.getQuantity().getValue(), is(y1));
final Coordinate lcY = xbEnvelope.getLowerCorner().getVector().getCoordinateArray(1);
assertThat(lcY.getName(), is(northing));
assertThat(lcY.getQuantity().getAxisID(), is(yAxisId));
assertThat(lcY.getQuantity().getUom().getCode(), is(uom));
assertThat(lcY.getQuantity().getValue(), is(x1));
final Coordinate ucX = xbEnvelope.getUpperCorner().getVector().getCoordinateArray(0);
assertThat(ucX.getName(), is(easting));
assertThat(ucX.getQuantity().getAxisID(), is(xAxisId));
assertThat(ucX.getQuantity().getUom().getCode(), is(uom));
assertThat(ucX.getQuantity().getValue(), is(y2));
final Coordinate ucY = xbEnvelope.getUpperCorner().getVector().getCoordinateArray(1);
assertThat(ucY.getName(), is(northing));
assertThat(ucY.getQuantity().getAxisID(), is(yAxisId));
assertThat(ucY.getQuantity().getUom().getCode(), is(uom));
assertThat(ucY.getQuantity().getValue(), is(x2));
assertThat(xbEnvelope.isSetReferenceFrame(), is(true));
assertThat(xbEnvelope.getReferenceFrame(), is("" + srid));
}
use of org.locationtech.jts.geom.Envelope in project arctic-sea by 52North.
the class FesEncoderv20Test method should_return_BBoxType_for_spatialFilter.
// @Test
// deactivated until test fails on build server.
public final void should_return_BBoxType_for_spatialFilter() throws EncodingException {
final SpatialFilter filter = new SpatialFilter();
filter.setOperator(SpatialOperator.BBOX);
filter.setGeometry(new GeometryFactory().toGeometry(new Envelope(1, 2, 3, 4)));
filter.setValueReference("valueReference");
final XmlObject encode = fesEncoder.encode(filter);
assertThat(encode, is(instanceOf(BBOXType.class)));
final BBOXType xbBBox = (BBOXType) encode;
assertThat(xbBBox.isSetExpression(), is(TRUE));
}
use of org.locationtech.jts.geom.Envelope in project h2database by h2database.
the class MVSpatialIndex method getKey.
private SpatialKey getKey(SearchRow row) {
Value v = row.getValue(columnIds[0]);
if (v == ValueNull.INSTANCE) {
return new SpatialKey(row.getKey());
}
Geometry g = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getGeometryNoCopy();
Envelope env = g.getEnvelopeInternal();
return new SpatialKey(row.getKey(), (float) env.getMinX(), (float) env.getMaxX(), (float) env.getMinY(), (float) env.getMaxY());
}
use of org.locationtech.jts.geom.Envelope 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.Envelope 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;
}
Aggregations