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);
}
}
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();
}
}
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);
}
}
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();
}
}
Aggregations