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 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.Coordinate in project neo4j by neo4j.
the class Neo4jJsonCodecTest method testGeometryWriting.
@Test
void testGeometryWriting() throws IOException {
// Given
List<Coordinate> points = new ArrayList<>();
points.add(new Coordinate(1, 2));
points.add(new Coordinate(2, 3));
Geometry value = SpatialMocks.mockGeometry("LineString", points, mockCartesian());
// When
jsonCodec.writeValue(jsonGenerator, value);
// Then
verify(jsonGenerator, times(3)).writeEndObject();
}
use of org.neo4j.graphdb.spatial.Coordinate in project neo4j by neo4j.
the class ExecutionResultSerializerTest method shouldErrorWhenSerializingUnknownGeometryType.
@Test
void shouldErrorWhenSerializingUnknownGeometryType() {
// given
var points = List.of(new Coordinate(1, 2), new Coordinate(2, 3));
var row = Map.of("geom", SpatialMocks.mockGeometry("LineString", points, mockCartesian()));
// when
var e = assertThrows(RuntimeException.class, () -> {
writeStatementStart(serializer, "geom");
writeRecord(serializer, row, "geom");
});
writeError(serializer, Status.Statement.ExecutionFailed, e.getMessage());
writeTransactionInfo(serializer);
// then
String result = output.toString(UTF_8);
assertThat(result).startsWith("{\"results\":[{\"columns\":[\"geom\"],\"data\":[" + "{\"row\":[{\"type\":\"LineString\",\"coordinates\":[[1.0,2.0],[2.0,3.0]],\"crs\":" + "{\"srid\":7203,\"name\":\"cartesian\",\"type\":\"link\",\"properties\":" + "{\"href\":\"http://spatialreference.org/ref/sr-org/7203/ogcwkt/\",\"type\":\"ogcwkt\"}}}],\"meta\":[]}]}]," + "\"errors\":[{\"code\":\"Neo.DatabaseError.Statement.ExecutionFailed\"," + "\"message\":\"Unsupported Geometry type: type=MockGeometry, value=LineString\"");
}
use of org.neo4j.graphdb.spatial.Coordinate 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.Coordinate in project neo4j by neo4j.
the class ExecutionResultSerializerTest method shouldSerializePointsAsListOfMapsOfProperties.
@Test
public void shouldSerializePointsAsListOfMapsOfProperties() throws Exception {
// given
ByteArrayOutputStream output = new ByteArrayOutputStream();
ExecutionResultSerializer serializer = getSerializerWith(output);
List<Coordinate> points = new ArrayList<>();
points.add(new Coordinate(1, 2));
points.add(new Coordinate(2, 3));
Result executionResult = mockExecutionResult(map("geom", new MockPoint(12.3, 45.6, mockWGS84())), map("geom", new MockPoint(123, 456, mockCartesian())), map("geom", new MockGeometry("LineString", points, mockCartesian())));
// when
serializer.statementResult(executionResult, false);
serializer.finish();
// then
String result = output.toString(UTF_8.name());
assertEquals("{\"results\":[{\"columns\":[\"geom\"],\"data\":[" + "{\"row\":[{\"type\":\"Point\",\"coordinates\":[12.3,45.6],\"crs\":" + "{\"name\":\"WGS-84\",\"type\":\"link\",\"properties\":" + "{\"href\":\"http://spatialreference.org/ref/epsg/4326/ogcwkt/\",\"type\":\"ogcwkt\"}" + "}}],\"meta\":[null]}," + "{\"row\":[{\"type\":\"Point\",\"coordinates\":[123.0,456.0],\"crs\":" + "{\"name\":\"cartesian\",\"type\":\"link\",\"properties\":" + "{\"href\":\"http://spatialreference.org/ref/sr-org/7203/ogcwkt/\",\"type\":\"ogcwkt\"}" + "}}],\"meta\":[null]}," + "{\"row\":[{\"type\":\"LineString\",\"coordinates\":[[1.0,2.0],[2.0,3.0]],\"crs\":" + "{\"name\":\"cartesian\",\"type\":\"link\",\"properties\":" + "{\"href\":\"http://spatialreference.org/ref/sr-org/7203/ogcwkt/\",\"type\":\"ogcwkt\"}" + "}}],\"meta\":[null]}" + "]}],\"errors\":[]}", result);
}
Aggregations