Search in sources :

Example 26 with ObjectMapper

use of org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper in project janusgraph by JanusGraph.

the class GeoshapeTest method testGeoJsonLine.

@Test
public void testGeoJsonLine() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" + "  \"type\": \"Feature\",\n" + "  \"geometry\": {\n" + "    \"type\": \"LineString\",\n" + "    \"coordinates\": [[20.5, 10.5],[22.5, 10.5],[22.5, 12.5]]\n" + "  },\n" + "  \"properties\": {\n" + "    \"name\": \"Dinagat Islands\"\n" + "  }\n" + "}", HashMap.class);
    assertEquals(Geoshape.line(Arrays.asList(new double[][] { { 20.5, 10.5 }, { 22.5, 10.5 }, { 22.5, 12.5 } })), s.convert(json));
}
Also used : Geoshape(org.janusgraph.core.attribute.Geoshape) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 27 with ObjectMapper

use of org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper in project janusgraph by JanusGraph.

the class GeoshapeTest method testGeoJsonMultiLineString.

@Test
public void testGeoJsonMultiLineString() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" + "  \"type\": \"Feature\",\n" + "  \"geometry\": {\n" + "    \"type\": \"MultiLineString\",\n" + "    \"coordinates\": [[[100.0,0.0],[101.0, 1.0]],[[102.0,2.0],[103.0,3.0]]]\n" + "  }" + "}", HashMap.class);
    assertEquals(HELPER.geoshape(GF.createMultiLineString(new LineString[] { GF.createLineString(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 1) }), GF.createLineString(new Coordinate[] { new Coordinate(102, 2), new Coordinate(103, 3) }) })), s.convert(json));
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) Geoshape(org.janusgraph.core.attribute.Geoshape) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 28 with ObjectMapper

use of org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper in project janusgraph by JanusGraph.

the class GeoshapeTest method testGeoJsonPointNotParsable.

@Test
public void testGeoJsonPointNotParsable() throws IOException {
    assertThrows(IllegalArgumentException.class, () -> {
        GeoshapeSerializer s = new GeoshapeSerializer();
        Map json = new ObjectMapper().readValue("{\n" + "  \"type\": \"Feature\",\n" + "  \"geometry\": {\n" + "    \"type\": \"Point\",\n" + "    \"coordinates\": [20.5, \"10.5\"]\n" + "  },\n" + "  \"properties\": {\n" + "    \"name\": \"Dinagat Islands\"\n" + "  }\n" + "}", HashMap.class);
        s.convert(json);
    });
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 29 with ObjectMapper

use of org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper in project janusgraph by JanusGraph.

the class GeoshapeTest method testGeoJsonLine.

@Test
public void testGeoJsonLine() throws IOException {
    GeoshapeSerializer s = new GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" + "  \"type\": \"Feature\",\n" + "  \"geometry\": {\n" + "    \"type\": \"LineString\",\n" + "    \"coordinates\": [[20.5, 10.5],[22.5, 10.5],[22.5, 12.5]]\n" + "  },\n" + "  \"properties\": {\n" + "    \"name\": \"Dinagat Islands\"\n" + "  }\n" + "}", HashMap.class);
    assertEquals(Geoshape.line(Arrays.asList(new double[][] { { 20.5, 10.5 }, { 22.5, 10.5 }, { 22.5, 12.5 } })), s.convert(json));
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 30 with ObjectMapper

use of org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper in project janusgraph by JanusGraph.

the class GeoshapeTest method testGeoJsonBox.

@Test
public void testGeoJsonBox() throws IOException {
    GeoshapeSerializer s = new GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" + "  \"type\": \"Feature\",\n" + "  \"geometry\": {\n" + "    \"type\": \"Polygon\",\n" + "    \"coordinates\": [[20.5, 10.5],[22.5, 10.5],[22.5, 12.5],[20.5, 12.5]]\n" + "  },\n" + "  \"properties\": {\n" + "    \"name\": \"Dinagat Islands\"\n" + "  }\n" + "}", HashMap.class);
    assertEquals(Geoshape.box(10.5, 20.5, 12.5, 22.5), s.convert(json));
    // Try the reverse order points
    json = new ObjectMapper().readValue("{\n" + "  \"type\": \"Feature\",\n" + "  \"geometry\": {\n" + "    \"type\": \"Polygon\",\n" + "    \"coordinates\": [[20.5, 12.5],[22.5, 12.5],[22.5, 10.5],[20.5, 10.5]]\n" + "  },\n" + "  \"properties\": {\n" + "    \"name\": \"Dinagat Islands\"\n" + "  }\n" + "}", HashMap.class);
    assertEquals(Geoshape.box(10.5, 20.5, 12.5, 22.5), s.convert(json));
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectMapper (org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper)35 HashMap (java.util.HashMap)26 Map (java.util.Map)26 Geoshape (org.janusgraph.core.attribute.Geoshape)14 Test (org.junit.Test)14 Test (org.junit.jupiter.api.Test)14 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 Coordinate (org.locationtech.jts.geom.Coordinate)4 HttpHost (org.apache.http.HttpHost)3 HttpDelete (org.apache.http.client.methods.HttpDelete)3 LinearRing (com.vividsolutions.jts.geom.LinearRing)2 SimpleModule (org.apache.tinkerpop.shaded.jackson.databind.module.SimpleModule)2 Before (org.junit.Before)2 LinearRing (org.locationtech.jts.geom.LinearRing)2 JtsSpatialContext (org.locationtech.spatial4j.context.jts.JtsSpatialContext)2 IOException (java.io.IOException)1 List (java.util.List)1 UUID (java.util.UUID)1 Neo4jIndexHandler (nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jIndexHandler)1 LogEntryFactory (nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory)1