Search in sources :

Example 6 with ValueGeometry

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

the class TestSpatial method testWKB.

/**
 * Test serialization of Z and SRID values.
 */
private void testWKB() {
    ValueGeometry geom3d = ValueGeometry.get("POLYGON ((67 13 6, 67 18 5, 59 18 4, 59 13 6,  67 13 6))", 27572);
    ValueGeometry copy = ValueGeometry.get(geom3d.getBytes());
    assertEquals(6, copy.getGeometry().getCoordinates()[0].z);
    assertEquals(5, copy.getGeometry().getCoordinates()[1].z);
    assertEquals(4, copy.getGeometry().getCoordinates()[2].z);
    // Test SRID
    copy = ValueGeometry.get(geom3d.getBytes());
    assertEquals(27572, copy.getGeometry().getSRID());
}
Also used : ValueGeometry(org.h2.value.ValueGeometry)

Example 7 with ValueGeometry

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

the class TestSpatial method testEquals.

/**
 * Test equality method on ValueGeometry
 */
private void testEquals() {
    // 3d equality test
    ValueGeometry geom3d = ValueGeometry.get("POLYGON ((67 13 6, 67 18 5, 59 18 4, 59 13 6,  67 13 6))");
    ValueGeometry geom2d = ValueGeometry.get("POLYGON ((67 13, 67 18, 59 18, 59 13,  67 13))");
    assertFalse(geom3d.equals(geom2d));
    // SRID equality test
    GeometryFactory geometryFactory = new GeometryFactory();
    Geometry geometry = geometryFactory.createPoint(new Coordinate(0, 0));
    geometry.setSRID(27572);
    ValueGeometry valueGeometry = ValueGeometry.getFromGeometry(geometry);
    Geometry geometry2 = geometryFactory.createPoint(new Coordinate(0, 0));
    geometry2.setSRID(5326);
    ValueGeometry valueGeometry2 = ValueGeometry.getFromGeometry(geometry2);
    assertFalse(valueGeometry.equals(valueGeometry2));
    ValueGeometry valueGeometry3 = ValueGeometry.getFromGeometry(geometry);
    assertEquals(valueGeometry, valueGeometry3);
    assertEquals(geometry.getSRID(), valueGeometry3.getGeometry().getSRID());
    // Check illegal geometry (no WKB representation)
    try {
        ValueGeometry.get("POINT EMPTY");
        fail("expected this to throw IllegalArgumentException");
    } catch (IllegalArgumentException ex) {
    // expected
    }
}
Also used : ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) ValueGeometry(org.h2.value.ValueGeometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 8 with ValueGeometry

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

the class GridH2SpatialIndex method findByGeometry.

/**
 * {@inheritDoc}
 */
@Override
public Cursor findByGeometry(TableFilter filter, SearchRow first, SearchRow last, SearchRow intersection) {
    Value v = intersection.getValue(columnIds[0]);
    Geometry g = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getGeometry();
    int seg = segmentsCount() == 1 ? 0 : H2Utils.context(filter.getSession()).segment();
    GridCursor<IndexRow> cursor = delegate.findByGeometry(seg, filter, g);
    GridCursor<H2Row> h2cursor = new IndexValueCursor<>(cursor, this::mapIndexRow);
    return new H2Cursor(h2cursor);
}
Also used : ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) ValueGeometry(org.h2.value.ValueGeometry) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) H2Cursor(org.apache.ignite.internal.processors.query.h2.H2Cursor) Value(org.h2.value.Value) IndexValueCursor(org.apache.ignite.internal.cache.query.index.sorted.IndexValueCursor)

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