Search in sources :

Example 1 with CRS

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

the class Neo4jJsonCodec method writeValue.

@Override
public void writeValue(JsonGenerator out, Object value) throws IOException {
    if (value instanceof PropertyContainer) {
        writePropertyContainer(out, (PropertyContainer) value, TransactionStateChecker.create(container));
    } else if (value instanceof Path) {
        writePath(out, ((Path) value).iterator(), TransactionStateChecker.create(container));
    } 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<>(), "name", crs.getType(), "type", "link", "properties", genericMap(new LinkedHashMap<>(), "href", crs.getHref() + "ogcwkt/", "type", "ogcwkt")));
    } else {
        super.writeValue(out, value);
    }
}
Also used : Path(org.neo4j.graphdb.Path) Geometry(org.neo4j.graphdb.spatial.Geometry) PropertyContainer(org.neo4j.graphdb.PropertyContainer) Coordinate(org.neo4j.graphdb.spatial.Coordinate) CRS(org.neo4j.graphdb.spatial.CRS) Point(org.neo4j.graphdb.spatial.Point) LinkedHashMap(java.util.LinkedHashMap) MapUtil.genericMap(org.neo4j.helpers.collection.MapUtil.genericMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with CRS

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

the class GraphDatabaseServiceExecuteTest method shouldNotReturnInternalCartesianPointType.

@Test
void shouldNotReturnInternalCartesianPointType() {
    // when
    try (Transaction transaction = db.beginTx()) {
        Result execute = transaction.execute("RETURN point({x: 13.37, y: 13.37, crs:'cartesian'}) AS p");
        // then
        Object obj = execute.next().get("p");
        assertThat(obj, Matchers.instanceOf(Point.class));
        Point point = (Point) obj;
        assertThat(point.getCoordinate(), equalTo(new Coordinate(13.37, 13.37)));
        CRS crs = point.getCRS();
        assertThat(crs.getCode(), equalTo(7203));
        assertThat(crs.getType(), equalTo("cartesian"));
        assertThat(crs.getHref(), equalTo("http://spatialreference.org/ref/sr-org/7203/"));
        transaction.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Coordinate(org.neo4j.graphdb.spatial.Coordinate) CRS(org.neo4j.graphdb.spatial.CRS) Point(org.neo4j.graphdb.spatial.Point) Result(org.neo4j.graphdb.Result) Test(org.junit.jupiter.api.Test)

Example 3 with CRS

use of org.neo4j.graphdb.spatial.CRS 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)

Example 4 with CRS

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

the class GraphDatabaseServiceExecuteTest method shouldNotReturnInternalGeographicPointType.

@Test
void shouldNotReturnInternalGeographicPointType() {
    try (Transaction transaction = db.beginTx()) {
        // when
        Result execute = transaction.execute("RETURN point({longitude: 144.317718, latitude: -37.031738}) AS p");
        // then
        Object obj = execute.next().get("p");
        assertThat(obj, Matchers.instanceOf(Point.class));
        Point point = (Point) obj;
        assertThat(point.getCoordinate().getCoordinate().get(0), equalTo(144.317718));
        assertThat(point.getCoordinate().getCoordinate().get(1), equalTo(-37.031738));
        CRS crs = point.getCRS();
        assertThat(crs.getCode(), equalTo(4326));
        assertThat(crs.getType(), equalTo("wgs-84"));
        assertThat(crs.getHref(), equalTo("http://spatialreference.org/ref/epsg/4326/"));
        transaction.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) CRS(org.neo4j.graphdb.spatial.CRS) Point(org.neo4j.graphdb.spatial.Point) Result(org.neo4j.graphdb.Result) Test(org.junit.jupiter.api.Test)

Aggregations

CRS (org.neo4j.graphdb.spatial.CRS)4 Point (org.neo4j.graphdb.spatial.Point)4 Coordinate (org.neo4j.graphdb.spatial.Coordinate)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Test (org.junit.jupiter.api.Test)2 Path (org.neo4j.graphdb.Path)2 Result (org.neo4j.graphdb.Result)2 Transaction (org.neo4j.graphdb.Transaction)2 Geometry (org.neo4j.graphdb.spatial.Geometry)2 Temporal (java.time.temporal.Temporal)1 TemporalAmount (java.time.temporal.TemporalAmount)1 Entity (org.neo4j.graphdb.Entity)1 PropertyContainer (org.neo4j.graphdb.PropertyContainer)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