Search in sources :

Example 6 with Point

use of org.neo4j.graphdb.spatial.Point in project neo4j by neo4j.

the class TestPropertyTypes method testPointTypeWithOneOtherProperty.

@Test
void testPointTypeWithOneOtherProperty() {
    Point point = Values.pointValue(Cartesian, 1, 1);
    String key = "location";
    try (Transaction transaction = getGraphDb().beginTx()) {
        node1 = transaction.getNodeById(node1.getId());
        node1.setProperty("prop1", 1);
        node1.setProperty(key, point);
        transaction.commit();
    }
    try (Transaction transaction = getGraphDb().beginTx()) {
        Object property = transaction.getNodeById(node1.getId()).getProperty(key);
        assertEquals(point, property);
        transaction.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Point(org.neo4j.graphdb.spatial.Point) Test(org.junit.jupiter.api.Test)

Example 7 with Point

use of org.neo4j.graphdb.spatial.Point in project neo4j by neo4j.

the class TestPropertyTypes method test3DPointType.

@Test
void test3DPointType() {
    Point point = Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 1, 1, 1);
    String key = "location";
    try (Transaction transaction = getGraphDb().beginTx()) {
        transaction.getNodeById(node1.getId()).setProperty(key, point);
        transaction.commit();
    }
    try (Transaction transaction = getGraphDb().beginTx()) {
        node1 = transaction.getNodeById(node1.getId());
        Object property = node1.getProperty(key);
        assertEquals(point, property);
        transaction.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Point(org.neo4j.graphdb.spatial.Point) Test(org.junit.jupiter.api.Test)

Example 8 with Point

use of org.neo4j.graphdb.spatial.Point in project neo4j by neo4j.

the class PointTypeIT method shouldWorkWithPoint2DArrays.

@Test
public void shouldWorkWithPoint2DArrays() throws Exception {
    HTTP.Response response = runQuery("create (:Node {points: [point({x:1, y:1}), point({x:2, y:2}), point({x: 3.0, y: 3.0})]})");
    assertEquals(200, response.status());
    assertNoErrors(response);
    var db = container().getDefaultDatabase();
    try (Transaction tx = db.beginTx()) {
        for (Node node : tx.getAllNodes()) {
            if (node.hasLabel(label("Node")) && node.hasProperty("points")) {
                Point[] points = (Point[]) node.getProperty("points");
                verifyPoint(points[0], Cartesian, 1.0, 1.0);
                verifyPoint(points[1], Cartesian, 2.0, 2.0);
                verifyPoint(points[2], Cartesian, 3.0, 3.0);
            }
        }
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) HTTP(org.neo4j.test.server.HTTP) Point(org.neo4j.graphdb.spatial.Point) Test(org.junit.jupiter.api.Test)

Example 9 with Point

use of org.neo4j.graphdb.spatial.Point in project neo4j by neo4j.

the class GraphDatabaseServiceExecuteTest method shouldNotReturnInternalPointWhenInMap.

@SuppressWarnings("unchecked")
@Test
void shouldNotReturnInternalPointWhenInMap() {
    try (Transaction transaction = db.beginTx()) {
        // when
        Result execute = transaction.execute("RETURN {p: point({longitude: 144.317718, latitude: -37.031738})} AS m");
        // then
        Map<String, Object> points = (Map<String, Object>) execute.next().get("m");
        assertThat(points.get("p"), Matchers.instanceOf(Point.class));
        transaction.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Point(org.neo4j.graphdb.spatial.Point) Map(java.util.Map) Result(org.neo4j.graphdb.Result) Test(org.junit.jupiter.api.Test)

Example 10 with Point

use of org.neo4j.graphdb.spatial.Point in project neo4j by neo4j.

the class GraphDatabaseServiceExecuteTest method shouldNotReturnInternalCartesianPointType.

@Test
void shouldNotReturnInternalCartesianPointType() {
    // when
    try (Transaction transaction = db.beginTx()) {
        Result execute = transaction.execute("RETURN point({x: 13.37, y: 13.37, crs:'cartesian'}) AS p");
        // then
        Object obj = execute.next().get("p");
        assertThat(obj, Matchers.instanceOf(Point.class));
        Point point = (Point) obj;
        assertThat(point.getCoordinate(), equalTo(new Coordinate(13.37, 13.37)));
        CRS crs = point.getCRS();
        assertThat(crs.getCode(), equalTo(7203));
        assertThat(crs.getType(), equalTo("cartesian"));
        assertThat(crs.getHref(), equalTo("http://spatialreference.org/ref/sr-org/7203/"));
        transaction.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Coordinate(org.neo4j.graphdb.spatial.Coordinate) CRS(org.neo4j.graphdb.spatial.CRS) Point(org.neo4j.graphdb.spatial.Point) Result(org.neo4j.graphdb.Result) Test(org.junit.jupiter.api.Test)

Aggregations

Point (org.neo4j.graphdb.spatial.Point)29 Test (org.junit.jupiter.api.Test)20 Transaction (org.neo4j.graphdb.Transaction)15 Result (org.neo4j.graphdb.Result)7 CRS (org.neo4j.graphdb.spatial.CRS)4 Map (java.util.Map)3 TemporalAmount (java.time.temporal.TemporalAmount)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Test (org.junit.Test)2 Coordinate (org.neo4j.graphdb.spatial.Coordinate)2 CoordinateReferenceSystem (org.neo4j.values.storable.CoordinateReferenceSystem)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Duration (java.time.Duration)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 OffsetTime (java.time.OffsetTime)1 Period (java.time.Period)1 ZonedDateTime (java.time.ZonedDateTime)1