Search in sources :

Example 1 with GeographicPoint2d

use of org.neo4j.ogm.types.spatial.GeographicPoint2d 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 GeographicPoint2d

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

the class SpatialTestBase method convertPersistAndLoadGeographicPoint2dForRelationship.

@Test
public void convertPersistAndLoadGeographicPoint2dForRelationship() {
    Session session = sessionFactory.openSession();
    SomethingRelationship somethingRelated = new SomethingRelationship();
    GeographicPoint2d point = new GeographicPoint2d(1, 2);
    somethingRelated.setGeographicPoint2d(point);
    session.save(somethingRelated);
    session.clear();
    SomethingRelationship loaded = session.load(SomethingRelationship.class, somethingRelated.getId());
    assertThat(loaded.getGeographicPoint2d()).isEqualTo(point);
}
Also used : GeographicPoint2d(org.neo4j.ogm.types.spatial.GeographicPoint2d) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 3 with GeographicPoint2d

use of org.neo4j.ogm.types.spatial.GeographicPoint2d 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 4 with GeographicPoint2d

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

the class SpatialTestBase method convertPersistAndLoadGeographicPoint2d.

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

Example 5 with GeographicPoint2d

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

the class DistanceComparisonTestBase method filterForGeographicPoint2d.

@Test
public void filterForGeographicPoint2d() {
    Session session = sessionFactory.openSession();
    SomethingSpatial spatial = new SomethingSpatial();
    GeographicPoint2d centralStationLocation = new GeographicPoint2d(55.6093093, 13.0004377);
    spatial.setGeographicPoint2d(centralStationLocation);
    session.save(spatial);
    GeographicPoint2d office = new GeographicPoint2d(55.611851, 12.9949028);
    DistanceFromNativePoint distanceFromNativePoint = new DistanceFromNativePoint(office, 449);
    Filter filter = new Filter("geographicPoint2d", distanceComparisonFor(distanceFromNativePoint));
    filter.setOwnerEntityType(SomethingSpatial.class);
    Collection<SomethingSpatial> somethingSpatials = session.loadAll(SomethingSpatial.class, filter);
    assertThat(somethingSpatials).hasSize(1);
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) GeographicPoint2d(org.neo4j.ogm.types.spatial.GeographicPoint2d) SomethingSpatial(org.neo4j.ogm.persistence.types.nativetypes.SomethingSpatial) DistanceFromNativePoint(org.neo4j.ogm.cypher.function.DistanceFromNativePoint) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Aggregations

GeographicPoint2d (org.neo4j.ogm.types.spatial.GeographicPoint2d)11 Test (org.junit.Test)10 Session (org.neo4j.ogm.session.Session)6 CartesianPoint2d (org.neo4j.ogm.types.spatial.CartesianPoint2d)5 CartesianPoint3d (org.neo4j.ogm.types.spatial.CartesianPoint3d)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