Search in sources :

Example 1 with CartesianPoint2d

use of org.neo4j.ogm.types.spatial.CartesianPoint2d in project neo4j-ogm by neo4j.

the class PointToBoltValueAdapter method apply.

@Override
public Point apply(AbstractPoint object) {
    Value value;
    if (object instanceof CartesianPoint2d) {
        CartesianPoint2d point = (CartesianPoint2d) object;
        value = Values.point(point.getSrid(), point.getX(), point.getY());
    } else if (object instanceof CartesianPoint3d) {
        CartesianPoint3d point = (CartesianPoint3d) object;
        value = Values.point(point.getSrid(), point.getX(), point.getY(), point.getZ());
    } else if (object instanceof GeographicPoint2d) {
        GeographicPoint2d point = (GeographicPoint2d) object;
        value = Values.point(point.getSrid(), point.getLongitude(), point.getLatitude());
    } else if (object instanceof GeographicPoint3d) {
        GeographicPoint3d point = (GeographicPoint3d) object;
        value = Values.point(point.getSrid(), point.getLongitude(), point.getLatitude(), point.getHeight());
    } else {
        throw new IllegalArgumentException("Unsupported point implementation: " + object.getClass());
    }
    return value.asPoint();
}
Also used : CartesianPoint3d(org.neo4j.ogm.types.spatial.CartesianPoint3d) CartesianPoint2d(org.neo4j.ogm.types.spatial.CartesianPoint2d) Value(org.neo4j.driver.Value) GeographicPoint3d(org.neo4j.ogm.types.spatial.GeographicPoint3d) GeographicPoint2d(org.neo4j.ogm.types.spatial.GeographicPoint2d)

Example 2 with CartesianPoint2d

use of org.neo4j.ogm.types.spatial.CartesianPoint2d in project neo4j-ogm by neo4j.

the class SpatialTestBase method spatialObjectsInMapsShouldWork.

@Test
public void spatialObjectsInMapsShouldWork() {
    Session session = sessionFactory.openSession();
    SomethingSpatial spatial = new SomethingSpatial();
    GeographicPoint2d geographicPoint2d = new GeographicPoint2d(1, 2);
    GeographicPoint3d geographicPoint3d = new GeographicPoint3d(1, 2, 3);
    CartesianPoint2d cartesianPoint2d = new CartesianPoint2d(1, 2);
    CartesianPoint3d cartesianPoint3d = new CartesianPoint3d(1, 2, 3);
    spatial.addProperty("geographicPoint2d", geographicPoint2d);
    spatial.addProperty("geographicPoint3d", geographicPoint3d);
    spatial.addProperty("cartesianPoint2d", cartesianPoint2d);
    spatial.addProperty("cartesianPoint3d", cartesianPoint3d);
    session.save(spatial);
    session.clear();
    SomethingSpatial loaded = session.load(SomethingSpatial.class, spatial.getId());
    assertThat(loaded.getProperties()).containsEntry("geographicPoint2d", geographicPoint2d);
    assertThat(loaded.getProperties()).containsEntry("geographicPoint3d", geographicPoint3d);
    assertThat(loaded.getProperties()).containsEntry("cartesianPoint2d", cartesianPoint2d);
    assertThat(loaded.getProperties()).containsEntry("cartesianPoint3d", cartesianPoint3d);
}
Also used : CartesianPoint3d(org.neo4j.ogm.types.spatial.CartesianPoint3d) CartesianPoint2d(org.neo4j.ogm.types.spatial.CartesianPoint2d) GeographicPoint3d(org.neo4j.ogm.types.spatial.GeographicPoint3d) GeographicPoint2d(org.neo4j.ogm.types.spatial.GeographicPoint2d) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 3 with CartesianPoint2d

use of org.neo4j.ogm.types.spatial.CartesianPoint2d in project neo4j-ogm by neo4j.

the class PointToEmbeddedValueAdapterTest method mappingShouldWork.

@Test
public void mappingShouldWork() {
    PointToEmbeddedValueAdapter adapter = new PointToEmbeddedValueAdapter();
    Point point;
    point = adapter.apply(new GeographicPoint2d(10, 20));
    Assertions.assertThat(point.getCRS().getCode()).isEqualTo(4326);
    Assertions.assertThat(point.getCoordinate().getCoordinate().get(0)).isEqualTo(20.0);
    Assertions.assertThat(point.getCoordinate().getCoordinate().get(1)).isEqualTo(10.0);
    point = adapter.apply(new CartesianPoint2d(10, 20));
    Assertions.assertThat(point.getCRS().getCode()).isEqualTo(7203);
    Assertions.assertThat(point.getCoordinate().getCoordinate().get(0)).isEqualTo(10.0);
    Assertions.assertThat(point.getCoordinate().getCoordinate().get(1)).isEqualTo(20.0);
    point = adapter.apply(new GeographicPoint3d(10.0, 20.0, 30));
    Assertions.assertThat(point.getCRS().getCode()).isEqualTo(4979);
    Assertions.assertThat(point.getCoordinate().getCoordinate().get(0)).isEqualTo(20.0);
    Assertions.assertThat(point.getCoordinate().getCoordinate().get(1)).isEqualTo(10.0);
    Assertions.assertThat(point.getCoordinate().getCoordinate().get(2)).isEqualTo(30.0);
    point = adapter.apply(new CartesianPoint3d(10.0, 20.0, 30));
    Assertions.assertThat(point.getCRS().getCode()).isEqualTo(9157);
    Assertions.assertThat(point.getCoordinate().getCoordinate().get(0)).isEqualTo(10.0);
    Assertions.assertThat(point.getCoordinate().getCoordinate().get(1)).isEqualTo(20.0);
    Assertions.assertThat(point.getCoordinate().getCoordinate().get(2)).isEqualTo(30.0);
}
Also used : CartesianPoint3d(org.neo4j.ogm.types.spatial.CartesianPoint3d) CartesianPoint2d(org.neo4j.ogm.types.spatial.CartesianPoint2d) GeographicPoint3d(org.neo4j.ogm.types.spatial.GeographicPoint3d) GeographicPoint2d(org.neo4j.ogm.types.spatial.GeographicPoint2d) Point(org.neo4j.graphdb.spatial.Point) Test(org.junit.Test)

Example 4 with CartesianPoint2d

use of org.neo4j.ogm.types.spatial.CartesianPoint2d in project neo4j-ogm by neo4j.

the class EmbeddedValueToPointAdapterTest method mappingShouldWork.

@Test
public void mappingShouldWork() {
    EmbeddedValueToPointAdapter adapter = new EmbeddedValueToPointAdapter();
    AbstractPoint point;
    point = adapter.apply(Values.pointValue(CoordinateReferenceSystem.WGS84, 10.0, 20.0));
    Assertions.assertThat(point).isInstanceOf(GeographicPoint2d.class);
    Assertions.assertThat(point.getSrid()).isEqualTo(4326);
    Assertions.assertThat(((GeographicPoint2d) point).getLatitude()).isEqualTo(20.0);
    Assertions.assertThat(((GeographicPoint2d) point).getLongitude()).isEqualTo(10.0);
    point = adapter.apply(Values.pointValue(CoordinateReferenceSystem.Cartesian, 10.0, 20.0));
    Assertions.assertThat(point).isInstanceOf(CartesianPoint2d.class);
    Assertions.assertThat(point.getSrid()).isEqualTo(7203);
    Assertions.assertThat(((CartesianPoint2d) point).getX()).isEqualTo(10.0);
    Assertions.assertThat(((CartesianPoint2d) point).getY()).isEqualTo(20.0);
    point = adapter.apply(Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 10.0, 20.0, 30));
    Assertions.assertThat(point).isInstanceOf(GeographicPoint3d.class);
    Assertions.assertThat(point.getSrid()).isEqualTo(4979);
    Assertions.assertThat(((GeographicPoint3d) point).getLatitude()).isEqualTo(20.0);
    Assertions.assertThat(((GeographicPoint3d) point).getLongitude()).isEqualTo(10.0);
    Assertions.assertThat(((GeographicPoint3d) point).getHeight()).isEqualTo(30.0);
    point = adapter.apply(Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 10.0, 20.0, 30));
    Assertions.assertThat(point).isInstanceOf(CartesianPoint3d.class);
    Assertions.assertThat(point.getSrid()).isEqualTo(9157);
    Assertions.assertThat(((CartesianPoint3d) point).getX()).isEqualTo(10.0);
    Assertions.assertThat(((CartesianPoint3d) point).getY()).isEqualTo(20.0);
    Assertions.assertThat(((CartesianPoint3d) point).getZ()).isEqualTo(30.0);
}
Also used : AbstractPoint(org.neo4j.ogm.types.spatial.AbstractPoint) CartesianPoint3d(org.neo4j.ogm.types.spatial.CartesianPoint3d) CartesianPoint2d(org.neo4j.ogm.types.spatial.CartesianPoint2d) GeographicPoint3d(org.neo4j.ogm.types.spatial.GeographicPoint3d) GeographicPoint2d(org.neo4j.ogm.types.spatial.GeographicPoint2d) Test(org.junit.Test)

Example 5 with CartesianPoint2d

use of org.neo4j.ogm.types.spatial.CartesianPoint2d in project neo4j-ogm by neo4j.

the class SpatialTestBase method convertPersistAndLoadCartesianPoint2d.

@Test
public void convertPersistAndLoadCartesianPoint2d() {
    Session session = sessionFactory.openSession();
    SomethingSpatial spatial = new SomethingSpatial();
    CartesianPoint2d point = new CartesianPoint2d(1, 2);
    spatial.setCartesianPoint2d(point);
    session.save(spatial);
    session.clear();
    SomethingSpatial loaded = session.load(SomethingSpatial.class, spatial.getId());
    assertThat(loaded.getCartesianPoint2d()).isEqualTo(point);
}
Also used : CartesianPoint2d(org.neo4j.ogm.types.spatial.CartesianPoint2d) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Aggregations

CartesianPoint2d (org.neo4j.ogm.types.spatial.CartesianPoint2d)9 Test (org.junit.Test)8 Session (org.neo4j.ogm.session.Session)5 CartesianPoint3d (org.neo4j.ogm.types.spatial.CartesianPoint3d)5 GeographicPoint2d (org.neo4j.ogm.types.spatial.GeographicPoint2d)5 GeographicPoint3d (org.neo4j.ogm.types.spatial.GeographicPoint3d)5 Filter (org.neo4j.ogm.cypher.Filter)2 DistanceFromNativePoint (org.neo4j.ogm.cypher.function.DistanceFromNativePoint)2 SomethingSpatial (org.neo4j.ogm.persistence.types.nativetypes.SomethingSpatial)2 Value (org.neo4j.driver.Value)1 Point (org.neo4j.driver.types.Point)1 Point (org.neo4j.graphdb.spatial.Point)1 AbstractPoint (org.neo4j.ogm.types.spatial.AbstractPoint)1