From 6c8f0eff7a85e765b7a83dc601c8e0a7cf700bf3 Mon Sep 17 00:00:00 2001 From: Rafael Biehler Date: Mon, 13 Jan 2025 19:04:37 +0100 Subject: [PATCH] NeoStatements now supports point syntax --- .../db/adapter/neo4j/util/NeoStatements.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/NeoStatements.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/NeoStatements.java index 26898f9e80..1772c1b38e 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/NeoStatements.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/NeoStatements.java @@ -39,6 +39,7 @@ import org.polypheny.db.type.entity.graph.PolyEdge.EdgeDirection; import org.polypheny.db.type.entity.graph.PolyNode; import org.polypheny.db.type.entity.graph.PolyPath; +import org.polypheny.db.type.entity.spatial.PolyPoint; /** * Helper classes, which are used to create cypher queries with a object representation. @@ -451,7 +452,26 @@ static NeoStatement _literalOrString( PolyValue value ) { return string_( value ); } else if ( value.isList() ) { return literal_( PolyString.of( String.format( "[%s]", value.asList().stream().map( value1 -> _literalOrString( (PolyValue) value1 ).build() ).collect( Collectors.joining( ", " ) ) ) ) ); - } else { + } + else if (value.isGeometry()){ + // Neo4j only supports PolyGeometry of type Point natively. We could choose to convert PolyGeometry + // to GeoJSON or WKT, but then the native Neo4j internal methods would no longer be able to work with + // the value. + assert value.asGeometry().isPoint() : "Neo4j only supports Point geometries natively"; + PolyPoint point = value.asGeometry().asPoint(); + int dimensions = Double.isNaN( point.getZ() ) ? 2 : 3; + String pointValues = switch (point.getSRID()) { + case 0 -> dimensions == 2 + ? "x: " + point.getX() + " , y: " + point.getY() + : "x: " + point.getX() + " , y: " + point.getY() + ", z: " + point.getZ(); + case 4326 -> "latitude: " + point.getX() + " , longitude: " + point.getY(); + case 4979 -> "latitude: " + point.getX() + " , longitude: " + point.getY() + " , height: " + point.getZ(); + default -> throw new IllegalArgumentException("Unsupported SRID: " + point.getSRID()); + }; + String pointString = "point({" + pointValues + "})"; + return literal_( PolyString.of(pointString) ); + } + else { return literal_( value ); } }