Search in sources :

Example 11 with Envelope

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));
}
Also used : ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) EnvelopeType(net.opengis.swe.x101.EnvelopeType) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) Coordinate(net.opengis.swe.x101.VectorType.Coordinate) XmlObject(org.apache.xmlbeans.XmlObject) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) Envelope(org.locationtech.jts.geom.Envelope) Test(org.junit.Test)

Example 12 with Envelope

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));
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) BBOXType(net.opengis.fes.x20.BBOXType) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) Envelope(org.locationtech.jts.geom.Envelope)

Example 13 with Envelope

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());
}
Also used : SpatialKey(org.h2.mvstore.rtree.SpatialKey) ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) ValueGeometry(org.h2.value.ValueGeometry) Value(org.h2.value.Value) VersionedValue(org.h2.mvstore.db.TransactionStore.VersionedValue) Envelope(org.locationtech.jts.geom.Envelope)

Example 14 with Envelope

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");
}
Also used : ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) Statement(java.sql.Statement) Connection(java.sql.Connection) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet) Envelope(org.locationtech.jts.geom.Envelope)

Example 15 with Envelope

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;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Envelope(org.locationtech.jts.geom.Envelope) Point(org.locationtech.jts.geom.Point) PointValuePair(org.n52.shetland.ogc.om.PointValuePair)

Aggregations

Envelope (org.locationtech.jts.geom.Envelope)20 ReferencedEnvelope (org.n52.shetland.util.ReferencedEnvelope)13 Test (org.junit.Test)11 Geometry (org.locationtech.jts.geom.Geometry)4 ValueGeometry (org.h2.value.ValueGeometry)3 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)3 XmlObject (org.apache.xmlbeans.XmlObject)2 SpatialKey (org.h2.mvstore.rtree.SpatialKey)2 Value (org.h2.value.Value)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 BigDecimal (java.math.BigDecimal)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 BBOXType (net.opengis.fes.x20.BBOXType)1 EnvelopeType (net.opengis.swe.x101.EnvelopeType)1 Coordinate (net.opengis.swe.x101.VectorType.Coordinate)1 VersionedValue (org.h2.mvstore.db.TransactionStore.VersionedValue)1 SimpleResultSet (org.h2.tools.SimpleResultSet)1