Search in sources :

Example 16 with Point

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

the class TestPropertyTypes method testPointTypeWithTwoOtherProperties.

@Test
void testPointTypeWithTwoOtherProperties() {
    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("prop2", 2);
        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 17 with Point

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

the class TestPropertyTypes method testPointArray.

@Test
void testPointArray() {
    Point[] array = { Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 1, 1, 1), Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 2, 1, 3) };
    String key = "testpointarray";
    try (Transaction transaction = getGraphDb().beginTx()) {
        transaction.getNodeById(node1.getId()).setProperty(key, array);
        transaction.commit();
    }
    try (Transaction transaction = getGraphDb().beginTx()) {
        node1 = transaction.getNodeById(node1.getId());
        Point[] propertyValue = (Point[]) node1.getProperty(key);
        assertEquals(array.length, propertyValue.length);
        for (int i = 0; i < array.length; i++) {
            assertEquals(array[i], propertyValue[i]);
        }
        node1.removeProperty(key);
        transaction.commit();
    }
    try (Transaction transaction = getGraphDb().beginTx()) {
        assertFalse(transaction.getNodeById(node1.getId()).hasProperty(key));
        transaction.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Point(org.neo4j.graphdb.spatial.Point) Point(org.neo4j.graphdb.spatial.Point) Test(org.junit.jupiter.api.Test)

Example 18 with Point

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

the class GeometryArrayType method asValue.

@Override
Value asValue(GenericKey state) {
    Point[] points = new Point[state.arrayLength];
    if (points.length > 0) {
        assertHasCoordinates(state);
        CoordinateReferenceSystem crs = CoordinateReferenceSystem.get((int) state.long1, (int) state.long2);
        int dimensions = dimensions(state);
        for (int i = 0; i < points.length; i++) {
            points[i] = GeometryType.asValue(state, crs, dimensions * i);
        }
    }
    return Values.pointArray(points);
}
Also used : GeometryType.putPoint(org.neo4j.kernel.impl.index.schema.GeometryType.putPoint) Point(org.neo4j.graphdb.spatial.Point) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) GeometryType.putPoint(org.neo4j.kernel.impl.index.schema.GeometryType.putPoint) Point(org.neo4j.graphdb.spatial.Point)

Example 19 with Point

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

the class ValueMapperTest method parameters.

private static Stream<AnyValue> parameters() {
    NodeValue node1 = nodeValue(1, stringArray(), EMPTY_MAP);
    NodeValue node2 = nodeValue(2, stringArray(), EMPTY_MAP);
    NodeValue node3 = nodeValue(3, stringArray(), EMPTY_MAP);
    RelationshipValue relationship1 = relationshipValue(100, node1, node2, stringValue("ONE"), EMPTY_MAP);
    RelationshipValue relationship2 = relationshipValue(200, node2, node2, stringValue("TWO"), EMPTY_MAP);
    return Stream.of(node1, relationship1, path(new NodeValue[] { node1, node2, node3 }, new RelationshipValue[] { relationship1, relationship2 }), map(new String[] { "alpha", "beta" }, new AnyValue[] { stringValue("one"), numberValue(2) }), NO_VALUE, list(numberValue(1), stringValue("fine"), node2), stringValue("hello world"), stringArray("hello", "brave", "new", "world"), booleanValue(false), booleanArray(new boolean[] { true, false, true }), charValue('\n'), charArray(new char[] { 'h', 'e', 'l', 'l', 'o' }), byteValue((byte) 3), byteArray(new byte[] { 0x00, (byte) 0x99, (byte) 0xcc }), shortValue((short) 42), shortArray(new short[] { 1337, (short) 0xcafe, (short) 0xbabe }), intValue(987654321), intArray(new int[] { 42, 11 }), longValue(9876543210L), longArray(new long[] { 0xcafebabe, 0x1ee7 }), floatValue(Float.MAX_VALUE), floatArray(new float[] { Float.NEGATIVE_INFINITY, Float.MIN_VALUE }), doubleValue(Double.MIN_NORMAL), doubleArray(new double[] { Double.POSITIVE_INFINITY, Double.MAX_VALUE }), datetime(2018, 1, 16, 10, 36, 43, 123456788, ZoneId.of("Europe/Stockholm")), localDateTime(2018, 1, 16, 10, 36, 43, 123456788), date(2018, 1, 16), time(10, 36, 43, 123456788, ZoneOffset.ofHours(1)), localTime(10, 36, 43, 123456788), duration(399, 4, 48424, 133701337), pointValue(Cartesian, 11, 32), pointArray(new Point[] { pointValue(Cartesian, 11, 32), pointValue(WGS84, 13, 56) }));
}
Also used : NodeValue(org.neo4j.values.virtual.NodeValue) VirtualNodeValue(org.neo4j.values.virtual.VirtualNodeValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) VirtualRelationshipValue(org.neo4j.values.virtual.VirtualRelationshipValue) Point(org.neo4j.graphdb.spatial.Point)

Example 20 with Point

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

the class GraphDatabaseServiceExecuteTest method shouldNotReturnInternalPointWhenInArray.

@SuppressWarnings("unchecked")
@Test
void shouldNotReturnInternalPointWhenInArray() {
    // when
    try (Transaction transaction = db.beginTx()) {
        Result execute = transaction.execute("RETURN [point({longitude: 144.317718, latitude: -37.031738})] AS ps");
        // then
        List<Point> points = (List<Point>) execute.next().get("ps");
        assertThat(points.get(0), Matchers.instanceOf(Point.class));
        transaction.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) List(java.util.List) 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