Search in sources :

Example 1 with ValueGeometry

use of org.h2.value.ValueGeometry in project ignite by apache.

the class GridH2SpatialIndex method getEnvelope.

/**
 * @param row Row.
 * @param rowId Row id.
 * @return Envelope.
 */
private SpatialKey getEnvelope(SearchRow row, long rowId) {
    Value v = row.getValue(columnIds[0]);
    Geometry g = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getGeometry();
    Envelope env = g.getEnvelopeInternal();
    return new SpatialKey(rowId, (float) env.getMinX(), (float) env.getMaxX(), (float) env.getMinY(), (float) env.getMaxY());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ValueGeometry(org.h2.value.ValueGeometry) SpatialKey(org.h2.mvstore.rtree.SpatialKey) ValueGeometry(org.h2.value.ValueGeometry) Value(org.h2.value.Value) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 2 with ValueGeometry

use of org.h2.value.ValueGeometry in project h2database by h2database.

the class SpatialTreeIndex method getKey.

private SpatialKey getKey(SearchRow row) {
    if (row == null) {
        return null;
    }
    Value v = row.getValue(columnIds[0]);
    if (v == ValueNull.INSTANCE) {
        return null;
    }
    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 : ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) SpatialKey(org.h2.mvstore.rtree.SpatialKey) ValueGeometry(org.h2.value.ValueGeometry) Value(org.h2.value.Value) Envelope(org.locationtech.jts.geom.Envelope)

Example 3 with ValueGeometry

use of org.h2.value.ValueGeometry 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 4 with ValueGeometry

use of org.h2.value.ValueGeometry in project h2database by h2database.

the class TestSpatial method testValueGeometryScript.

/**
 * Check ValueGeometry conversion into SQL script
 */
private void testValueGeometryScript() throws SQLException {
    ValueGeometry valueGeometry = ValueGeometry.get("POINT(1 1 5)");
    try (Connection conn = getConnection(URL)) {
        ResultSet rs = conn.createStatement().executeQuery("SELECT " + valueGeometry.getSQL());
        assertTrue(rs.next());
        Object obj = rs.getObject(1);
        ValueGeometry g = ValueGeometry.getFromGeometry(obj);
        assertTrue("got: " + g + " exp: " + valueGeometry, valueGeometry.equals(g));
    }
}
Also used : ValueGeometry(org.h2.value.ValueGeometry) Connection(java.sql.Connection) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet)

Example 5 with ValueGeometry

use of org.h2.value.ValueGeometry in project h2database by h2database.

the class TestSpatial method testHashCode.

private void testHashCode() {
    ValueGeometry geomA = ValueGeometry.get("POLYGON ((67 13 6, 67 18 5, 59 18 4, 59 13 6,  67 13 6))");
    ValueGeometry geomB = ValueGeometry.get("POLYGON ((67 13 6, 67 18 5, 59 18 4, 59 13 6,  67 13 6))");
    ValueGeometry geomC = ValueGeometry.get("POLYGON ((67 13 6, 67 18 5, 59 18 4, 59 13 5,  67 13 6))");
    assertEquals(geomA.hashCode(), geomB.hashCode());
    assertFalse(geomA.hashCode() == geomC.hashCode());
}
Also used : ValueGeometry(org.h2.value.ValueGeometry)

Aggregations

ValueGeometry (org.h2.value.ValueGeometry)8 Value (org.h2.value.Value)4 Geometry (org.locationtech.jts.geom.Geometry)4 SpatialKey (org.h2.mvstore.rtree.SpatialKey)3 Envelope (org.locationtech.jts.geom.Envelope)2 Envelope (com.vividsolutions.jts.geom.Envelope)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 IndexRow (org.apache.ignite.internal.cache.query.index.sorted.IndexRow)1 IndexValueCursor (org.apache.ignite.internal.cache.query.index.sorted.IndexValueCursor)1 H2Cursor (org.apache.ignite.internal.processors.query.h2.H2Cursor)1 VersionedValue (org.h2.mvstore.db.TransactionStore.VersionedValue)1 SimpleResultSet (org.h2.tools.SimpleResultSet)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)1