Skip to content

Commit

Permalink
NeoStatements now supports point syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
murermader committed Jan 13, 2025
1 parent 68ffca6 commit 6c8f0ef
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 );
}
}
Expand Down

0 comments on commit 6c8f0ef

Please sign in to comment.