Search in sources :

Example 16 with Geoshape

use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.

the class GeoToWktConverterTest method testConvertGeoshapeLineToWktString.

@Test
public void testConvertGeoshapeLineToWktString() throws BackendException {
    Geoshape l1 = Geoshape.line(Arrays.asList(new double[][] { { 48.9, 35.4 }, { 49.1, 35.6 } }));
    String wkt1 = "LINESTRING (48.9 35.4, 49.1 35.6)";
    String actualWkt1 = GeoToWktConverter.convertToWktString(l1);
    assertEquals(wkt1, actualWkt1);
}
Also used : Geoshape(org.janusgraph.core.attribute.Geoshape) LineString(com.vividsolutions.jts.geom.LineString) Test(org.junit.Test)

Example 17 with Geoshape

use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.

the class JanusGraphIoTest method assertGeoshape.

private void assertGeoshape(Function<Geoshape, Geoshape> makeGeoshape) {
    graph.traversal().E().has("place").toList().forEach(e -> {
        assertTrue(e.property("shape").isPresent());
        Geoshape place = (Geoshape) e.property("place").value();
        Geoshape expected = makeGeoshape.apply(place);
        Geoshape actual = (Geoshape) e.property("shape").value();
        assertEquals(expected, actual);
    });
}
Also used : Geoshape(org.janusgraph.core.attribute.Geoshape)

Example 18 with Geoshape

use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.

the class JanusGraphIoTest method addGeoshape.

private void addGeoshape(Function<Geoshape, Geoshape> makeGeoshape) {
    JanusGraphTransaction tx = graph.newTransaction();
    graph.traversal().E().has("place").toList().forEach(e -> {
        Geoshape place = (Geoshape) e.property("place").value();
        e.property("shape", makeGeoshape.apply(place));
    });
    tx.commit();
}
Also used : JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) Geoshape(org.janusgraph.core.attribute.Geoshape)

Example 19 with Geoshape

use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.

the class JanusGraphTest method testDataTypes.

/**
 * Test the different data types that JanusGraph supports natively and ensure that invalid data types aren't allowed
 */
@Test
public void testDataTypes() {
    clopen(option(CUSTOM_ATTRIBUTE_CLASS, "attribute10"), SpecialInt.class.getCanonicalName(), option(CUSTOM_SERIALIZER_CLASS, "attribute10"), SpecialIntSerializer.class.getCanonicalName());
    PropertyKey num = makeKey("num", SpecialInt.class);
    PropertyKey barr = makeKey("barr", byte[].class);
    PropertyKey booleanValue = makeKey("boolval", Boolean.class);
    PropertyKey birthday = makeKey("birthday", Instant.class);
    PropertyKey location = makeKey("location", Geoshape.class);
    PropertyKey boundary = makeKey("boundary", Geoshape.class);
    PropertyKey precise = makeKey("precise", Double.class);
    PropertyKey any = mgmt.makePropertyKey("any").cardinality(Cardinality.LIST).dataType(Object.class).make();
    try {
        // Not a valid data type - primitive
        makeKey("pint", int.class);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // Not a valid data type - interface
        makeKey("number", Number.class);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    finishSchema();
    clopen();
    booleanValue = tx.getPropertyKey("boolval");
    num = tx.getPropertyKey("num");
    barr = tx.getPropertyKey("barr");
    birthday = tx.getPropertyKey("birthday");
    location = tx.getPropertyKey("location");
    boundary = tx.getPropertyKey("boundary");
    precise = tx.getPropertyKey("precise");
    any = tx.getPropertyKey("any");
    assertEquals(Boolean.class, booleanValue.dataType());
    assertEquals(byte[].class, barr.dataType());
    assertEquals(Object.class, any.dataType());
    final Instant c = Instant.ofEpochSecond(1429225756);
    final Geoshape point = Geoshape.point(10.0, 10.0);
    final Geoshape shape = Geoshape.box(10.0, 10.0, 20.0, 20.0);
    JanusGraphVertex v = tx.addVertex();
    v.property(n(booleanValue), true);
    v.property(VertexProperty.Cardinality.single, n(birthday), c);
    v.property(VertexProperty.Cardinality.single, n(num), new SpecialInt(10));
    v.property(VertexProperty.Cardinality.single, n(barr), new byte[] { 1, 2, 3, 4 });
    v.property(VertexProperty.Cardinality.single, n(location), point);
    v.property(VertexProperty.Cardinality.single, n(boundary), shape);
    v.property(VertexProperty.Cardinality.single, n(precise), 10.12345);
    v.property(n(any), "Hello");
    v.property(n(any), 10L);
    int[] testArray = { 5, 6, 7 };
    v.property(n(any), testArray);
    // ######## VERIFICATION ##########
    assertTrue(v.<Boolean>value("boolval"));
    assertEquals(10, v.<SpecialInt>value("num").getValue());
    assertEquals(c, v.value("birthday"));
    assertEquals(4, v.<byte[]>value("barr").length);
    assertEquals(point, v.<Geoshape>value("location"));
    assertEquals(shape, v.<Geoshape>value("boundary"));
    assertEquals(10.12345, v.<Double>value("precise"), 0.000001);
    assertCount(3, v.properties("any"));
    for (Object prop : v.query().labels("any").properties()) {
        Object value = ((JanusGraphVertexProperty<?>) prop).value();
        if (value instanceof String)
            assertEquals("Hello", value);
        else if (value instanceof Long)
            assertEquals(10L, value);
        else if (value.getClass().isArray()) {
            assertTrue(Arrays.equals(testArray, (int[]) value));
        } else
            fail();
    }
    clopen();
    v = getV(tx, v);
    // ######## VERIFICATION (copied from above) ##########
    assertTrue(v.<Boolean>value("boolval"));
    assertEquals(10, v.<SpecialInt>value("num").getValue());
    assertEquals(c, v.value("birthday"));
    assertEquals(4, v.<byte[]>value("barr").length);
    assertEquals(point, v.<Geoshape>value("location"));
    assertEquals(shape, v.<Geoshape>value("boundary"));
    assertEquals(10.12345, v.<Double>value("precise"), 0.000001);
    assertCount(3, v.properties("any"));
    for (Object prop : v.query().labels("any").properties()) {
        Object value = ((JanusGraphVertexProperty<?>) prop).value();
        if (value instanceof String)
            assertEquals("Hello", value);
        else if (value instanceof Long)
            assertEquals(10L, value);
        else if (value.getClass().isArray()) {
            assertTrue(Arrays.equals(testArray, (int[]) value));
        } else
            fail();
    }
}
Also used : SpecialIntSerializer(org.janusgraph.graphdb.serializer.SpecialIntSerializer) SpecialInt(org.janusgraph.graphdb.serializer.SpecialInt) Instant(java.time.Instant) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Geoshape(org.janusgraph.core.attribute.Geoshape) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Aggregations

Geoshape (org.janusgraph.core.attribute.Geoshape)19 Test (org.junit.Test)12 LineString (com.vividsolutions.jts.geom.LineString)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)4 Instant (java.time.Instant)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 UUID (java.util.UUID)2 Cmp (org.janusgraph.core.attribute.Cmp)2 Geo (org.janusgraph.core.attribute.Geo)2 Mapping (org.janusgraph.core.schema.Mapping)2 JanusGraphPredicate (org.janusgraph.graphdb.query.JanusGraphPredicate)2 And (org.janusgraph.graphdb.query.condition.And)2 Condition (org.janusgraph.graphdb.query.condition.Condition)2 Not (org.janusgraph.graphdb.query.condition.Not)2 Or (org.janusgraph.graphdb.query.condition.Or)2 PredicateCondition (org.janusgraph.graphdb.query.condition.PredicateCondition)2