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