Search in sources :

Example 21 with Geometry

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

Example 22 with Geometry

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");
}
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 23 with Geometry

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);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) JsonNode(com.fasterxml.jackson.databind.JsonNode) GeoJSONDecodingException(org.n52.svalbard.coding.json.GeoJSONDecodingException) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 24 with Geometry

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;
}
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)

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

Aggregations

Geometry (org.locationtech.jts.geom.Geometry)34 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)9 XmlObject (org.apache.xmlbeans.XmlObject)8 ValueGeometry (org.h2.value.ValueGeometry)7 Coordinate (org.locationtech.jts.geom.Coordinate)7 XmlException (org.apache.xmlbeans.XmlException)6 GeometryValue (org.n52.shetland.ogc.om.values.GeometryValue)6 Test (org.junit.Test)5 Point (org.locationtech.jts.geom.Point)5 AbstractGeometry (org.n52.shetland.ogc.gml.AbstractGeometry)5 DecodingException (org.n52.svalbard.decode.exception.DecodingException)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)4 XmlCursor (org.apache.xmlbeans.XmlCursor)3 Envelope (org.locationtech.jts.geom.Envelope)3 ReferenceType (org.n52.shetland.ogc.gml.ReferenceType)3 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 MultiPointType (net.opengis.gml.x32.MultiPointType)2