Search in sources :

Example 1 with SimpleModule

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

the class GeoshapeTest method testGeoJsonSerialization.

@Test
public void testGeoJsonSerialization() throws IOException {
    SimpleModule module = new SimpleModule();
    module.addSerializer(new Geoshape.GeoshapeGsonSerializerV2d0());
    final ObjectMapper om = new ObjectMapper();
    om.registerModule(module);
    JtsSpatialContext context = (JtsSpatialContext) Geoshape.getSpatialContext();
    assertEquals("{\"type\":\"Point\",\"coordinates\":[20.5,10.5]}", om.writeValueAsString(Geoshape.point(10.5, 20.5)));
    assertEquals("{\"type\":\"Polygon\",\"coordinates\":[[[20.5,10.5],[20.5,12.5],[22.5,12.5],[22.5,10.5],[20.5,10.5]]]}", om.writeValueAsString(Geoshape.box(10.5, 20.5, 12.5, 22.5)));
    assertEquals("{\"type\":\"Circle\",\"coordinates\":[20.5,10.5],\"radius\":30.5,\"properties\":{\"radius_units\":\"km\"}}", om.writeValueAsString(Geoshape.circle(10.5, 20.5, 30.5)));
    assertEquals("{\"type\":\"LineString\",\"coordinates\":[[20.5,10.5],[22.5,10.5],[22.5,12.5]]}", om.writeValueAsString(Geoshape.line(Arrays.asList(new double[][] { { 20.5, 10.5 }, { 22.5, 10.5 }, { 22.5, 12.5 } }))));
    assertEquals("{\"type\":\"Polygon\",\"coordinates\":[[[20.5,10.5],[21.75,8],[22.5,10.5],[25,11.75],[22.5,12.5],[21,15],[20.5,12.5],[18,11.75],[20.5,10.5]]]}", om.writeValueAsString(Geoshape.polygon(Arrays.asList(new double[][] { { 20.5, 10.5 }, { 21.75, 8 }, { 22.5, 10.5 }, { 25, 11.75 }, { 22.5, 12.5 }, { 21, 15 }, { 20.5, 12.5 }, { 18, 11.75 }, { 20.5, 10.5 } }))));
    assertEquals("{\"type\":\"MultiPoint\",\"coordinates\":[[100,0],[101,1]]}", om.writeValueAsString(Geoshape.geoshape(context.getShapeFactory().makeShapeFromGeometry(GF.createMultiPoint(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 1) })))));
    assertEquals("{\"type\":\"MultiLineString\",\"coordinates\":[[[100,0],[101,1]],[[102,2],[103,3]]]}", om.writeValueAsString(Geoshape.geoshape(context.getShapeFactory().makeShapeFromGeometry(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) }) })))));
    assertEquals("{\"type\":\"MultiPolygon\",\"coordinates\":[[[[102,2],[103,2],[103,3],[102,3],[102,2]]],[[[100,0],[101,0],[101,1],[100,1],[100,0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]]}", om.writeValueAsString(Geoshape.geoshape(context.getShapeFactory().makeShapeFromGeometry(GF.createMultiPolygon(new Polygon[] { GF.createPolygon(new Coordinate[] { new Coordinate(102, 2), new Coordinate(103, 2), new Coordinate(103, 3), new Coordinate(102, 3), new Coordinate(102, 2) }), GF.createPolygon(GF.createLinearRing(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 0), new Coordinate(101, 1), new Coordinate(100, 1), new Coordinate(100, 0) }), new LinearRing[] { GF.createLinearRing(new Coordinate[] { new Coordinate(100.2, 0.2), new Coordinate(100.8, 0.2), new Coordinate(100.8, 0.8), new Coordinate(100.2, 0.8), new Coordinate(100.2, 0.2) }) }) })))));
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) SimpleModule(org.apache.tinkerpop.shaded.jackson.databind.module.SimpleModule) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) JtsSpatialContext(org.locationtech.spatial4j.context.jts.JtsSpatialContext) Test(org.junit.jupiter.api.Test)

Example 2 with SimpleModule

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

the class GeoshapeTest method testGeoJsonSerialization.

@Test
public void testGeoJsonSerialization() throws IOException {
    SimpleModule module = new SimpleModule();
    module.addSerializer(new Geoshape.GeoshapeGsonSerializerV2d0());
    final ObjectMapper om = new ObjectMapper();
    om.registerModule(module);
    JtsSpatialContext context = (JtsSpatialContext) Geoshape.getSpatialContext();
    assertEquals("{\"type\":\"Point\",\"coordinates\":[20.5,10.5]}", om.writeValueAsString(Geoshape.point(10.5, 20.5)));
    assertEquals("{\"type\":\"Polygon\",\"coordinates\": [[[20.5,10.5],[20.5,12.5],[22.5,12.5],[22.5,10.5],[20.5,10.5]]]}", om.writeValueAsString(Geoshape.box(10.5, 20.5, 12.5, 22.5)));
    assertEquals("{\"type\":\"Circle\",\"coordinates\":[20.5,10.5],\"radius\":30.5,\"properties\":{\"radius_units\":\"km\"}}", om.writeValueAsString(Geoshape.circle(10.5, 20.5, 30.5)));
    assertEquals("{\"type\":\"LineString\",\"coordinates\":[[20.5,10.5],[22.5,10.5],[22.5,12.5]]}", om.writeValueAsString(Geoshape.line(Arrays.asList(new double[][] { { 20.5, 10.5 }, { 22.5, 10.5 }, { 22.5, 12.5 } }))));
    assertEquals("{\"type\":\"Polygon\",\"coordinates\":[[[20.5,10.5],[21.75,8],[22.5,10.5],[25,11.75],[22.5,12.5],[21,15],[20.5,12.5],[18,11.75],[20.5,10.5]]]}", om.writeValueAsString(Geoshape.polygon(Arrays.asList(new double[][] { { 20.5, 10.5 }, { 21.75, 8 }, { 22.5, 10.5 }, { 25, 11.75 }, { 22.5, 12.5 }, { 21, 15 }, { 20.5, 12.5 }, { 18, 11.75 }, { 20.5, 10.5 } }))));
    assertEquals("{\"type\":\"MultiPoint\",\"coordinates\":[[100,0],[101,1]]}", om.writeValueAsString(Geoshape.geoshape(context.getShapeFactory().makeShapeFromGeometry(GF.createMultiPoint(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 1) })))));
    assertEquals("{\"type\":\"MultiLineString\",\"coordinates\":[[[100,0],[101,1]],[[102,2],[103,3]]]}", om.writeValueAsString(Geoshape.geoshape(context.getShapeFactory().makeShapeFromGeometry(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) }) })))));
    assertEquals("{\"type\":\"MultiPolygon\",\"coordinates\":[[[[102,2],[103,2],[103,3],[102,3],[102,2]]],[[[100,0],[101,0],[101,1],[100,1],[100,0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]]}", om.writeValueAsString(Geoshape.geoshape(context.getShapeFactory().makeShapeFromGeometry(GF.createMultiPolygon(new Polygon[] { GF.createPolygon(new Coordinate[] { new Coordinate(102, 2), new Coordinate(103, 2), new Coordinate(103, 3), new Coordinate(102, 3), new Coordinate(102, 2) }), GF.createPolygon(GF.createLinearRing(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 0), new Coordinate(101, 1), new Coordinate(100, 1), new Coordinate(100, 0) }), new LinearRing[] { GF.createLinearRing(new Coordinate[] { new Coordinate(100.2, 0.2), new Coordinate(100.8, 0.2), new Coordinate(100.8, 0.8), new Coordinate(100.2, 0.8), new Coordinate(100.2, 0.2) }) }) })))));
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) Geoshape(org.janusgraph.core.attribute.Geoshape) LinearRing(com.vividsolutions.jts.geom.LinearRing) SimpleModule(org.apache.tinkerpop.shaded.jackson.databind.module.SimpleModule) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) JtsSpatialContext(org.locationtech.spatial4j.context.jts.JtsSpatialContext) Test(org.junit.Test)

Aggregations

ObjectMapper (org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper)2 SimpleModule (org.apache.tinkerpop.shaded.jackson.databind.module.SimpleModule)2 JtsSpatialContext (org.locationtech.spatial4j.context.jts.JtsSpatialContext)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 LinearRing (com.vividsolutions.jts.geom.LinearRing)1 Geoshape (org.janusgraph.core.attribute.Geoshape)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 LinearRing (org.locationtech.jts.geom.LinearRing)1