Search in sources :

Example 6 with Coordinate

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

the class Neo4jJsonCodecTest method testGeometryWriting.

@Test
public void testGeometryWriting() throws IOException {
    //Given
    List<Coordinate> points = new ArrayList<>();
    points.add(new Coordinate(1, 2));
    points.add(new Coordinate(2, 3));
    Geometry value = new MockGeometry("LineString", points, mockCartesian());
    //When
    jsonCodec.writeValue(jsonGenerator, value);
    //Then
    verify(jsonGenerator, times(3)).writeEndObject();
}
Also used : Geometry(org.neo4j.graphdb.spatial.Geometry) Coordinate(org.neo4j.graphdb.spatial.Coordinate) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with Coordinate

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

the class Neo4jJsonCodec method writeValue.

@Override
public void writeValue(JsonGenerator out, Object value) throws IOException {
    if (value instanceof Entity) {
        var context = transactionHandle.getContext();
        TransactionStateChecker txStateChecker = TransactionStateChecker.create(context);
        writeEntity(out, (Entity) value, txStateChecker, context);
    } else if (value instanceof Path) {
        var context = transactionHandle.getContext();
        TransactionStateChecker txStateChecker = TransactionStateChecker.create(context);
        writePath(out, ((Path) value).iterator(), txStateChecker, context);
    } else if (value instanceof Iterable) {
        writeIterator(out, ((Iterable) value).iterator());
    } else if (value instanceof byte[]) {
        writeByteArray(out, (byte[]) value);
    } else if (value instanceof Map) {
        writeMap(out, (Map) value);
    } else if (value instanceof Geometry) {
        Geometry geom = (Geometry) value;
        Object coordinates = (geom instanceof Point) ? ((Point) geom).getCoordinate() : geom.getCoordinates();
        writeMap(out, genericMap(new LinkedHashMap<>(), "type", geom.getGeometryType(), "coordinates", coordinates, "crs", geom.getCRS()));
    } else if (value instanceof Coordinate) {
        Coordinate coordinate = (Coordinate) value;
        writeIterator(out, coordinate.getCoordinate().iterator());
    } else if (value instanceof CRS) {
        CRS crs = (CRS) value;
        writeMap(out, genericMap(new LinkedHashMap<>(), "srid", crs.getCode(), "name", crs.getType(), "type", "link", "properties", genericMap(new LinkedHashMap<>(), "href", crs.getHref() + "ogcwkt/", "type", "ogcwkt")));
    } else if (value instanceof Temporal || value instanceof TemporalAmount) {
        super.writeValue(out, value.toString());
    } else if (value != null && value.getClass().isArray() && supportedArrayType(value.getClass().getComponentType())) {
        writeReflectiveArray(out, value);
    } else {
        super.writeValue(out, value);
    }
}
Also used : Path(org.neo4j.graphdb.Path) Entity(org.neo4j.graphdb.Entity) TransactionStateChecker(org.neo4j.server.http.cypher.TransactionStateChecker) CRS(org.neo4j.graphdb.spatial.CRS) Point(org.neo4j.graphdb.spatial.Point) LinkedHashMap(java.util.LinkedHashMap) Geometry(org.neo4j.graphdb.spatial.Geometry) Temporal(java.time.temporal.Temporal) Coordinate(org.neo4j.graphdb.spatial.Coordinate) TemporalAmount(java.time.temporal.TemporalAmount) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MapUtil.genericMap(org.neo4j.internal.helpers.collection.MapUtil.genericMap)

Aggregations

Coordinate (org.neo4j.graphdb.spatial.Coordinate)7 Geometry (org.neo4j.graphdb.spatial.Geometry)4 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 CRS (org.neo4j.graphdb.spatial.CRS)3 Point (org.neo4j.graphdb.spatial.Point)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 Path (org.neo4j.graphdb.Path)2 Result (org.neo4j.graphdb.Result)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Temporal (java.time.temporal.Temporal)1 TemporalAmount (java.time.temporal.TemporalAmount)1 Entity (org.neo4j.graphdb.Entity)1 PropertyContainer (org.neo4j.graphdb.PropertyContainer)1 Transaction (org.neo4j.graphdb.Transaction)1 MapUtil.genericMap (org.neo4j.helpers.collection.MapUtil.genericMap)1 MapUtil.genericMap (org.neo4j.internal.helpers.collection.MapUtil.genericMap)1 TransactionStateChecker (org.neo4j.server.http.cypher.TransactionStateChecker)1