use of org.neo4j.graphdb.spatial.Geometry in project neo4j by neo4j.
the class GraphDatabaseServiceExecuteTest method shouldBeAbleToUseExternalGeometryAsParameterToQuery.
@Test
public void shouldBeAbleToUseExternalGeometryAsParameterToQuery() throws Exception {
// given a point created from public interface
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
Geometry geometry = makeFakePointAsGeometry(144.317718, -37.031738, makeWGS84());
// when passing as params to a distance function
Result result = graphDb.execute("RETURN distance(point({longitude: 144.317718, latitude: -37.031738}),{previous}) AS dist", map("previous", geometry));
// then
Double dist = (Double) result.next().get("dist");
assertThat(dist, equalTo(0.0));
}
use of org.neo4j.graphdb.spatial.Geometry 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.Geometry 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();
}
Aggregations