diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/RexImpTable.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/RexImpTable.java index 2a82f02647..4d201ba87c 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/RexImpTable.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/RexImpTable.java @@ -390,6 +390,7 @@ public Expression implement( RexToLixTranslator translator, RexCall call, ListST_Equals operator function: check that two {@link org.polypheny.db.type.entity.spatial.PolyGeometry} are equals + */ + ST_EQUALS( Function.class ), + /** * The ST_DWithin operator function: check if two {@link org.polypheny.db.type.entity.spatial.PolyGeometry} are withing the given distance */ diff --git a/core/src/main/java/org/polypheny/db/functions/GeoFunctions.java b/core/src/main/java/org/polypheny/db/functions/GeoFunctions.java index 014b7f6170..ee6241587c 100644 --- a/core/src/main/java/org/polypheny/db/functions/GeoFunctions.java +++ b/core/src/main/java/org/polypheny/db/functions/GeoFunctions.java @@ -238,6 +238,13 @@ public static PolyGeometry stBuffer( PolyGeometry geometry, PolyNumber distance, */ + @SuppressWarnings("UnusedDeclaration") + public static PolyBoolean stEquals( PolyGeometry g1, PolyGeometry g2 ) { + restrictToSrid( g1, g2 ); + return PolyBoolean.of( g1.equals( g2 ) ); + } + + @SuppressWarnings("UnusedDeclaration") public static PolyBoolean stDWithin( PolyGeometry g1, PolyGeometry g2, PolyNumber distance ) { restrictToSrid( g1, g2 ); diff --git a/core/src/main/java/org/polypheny/db/type/entity/spatial/PolyGeometry.java b/core/src/main/java/org/polypheny/db/type/entity/spatial/PolyGeometry.java index fa6292a379..6ddca9f1ff 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/spatial/PolyGeometry.java +++ b/core/src/main/java/org/polypheny/db/type/entity/spatial/PolyGeometry.java @@ -276,26 +276,17 @@ private void readGeometry( int srid, GeometryReaderFunction readerFunction ) thr protected PolyGeometryType getPolyGeometryType() { - switch ( jtsGeometry.getGeometryType() ) { - case Geometry.TYPENAME_POINT: - return PolyGeometryType.POINT; - case Geometry.TYPENAME_LINESTRING: - return PolyGeometryType.LINESTRING; - case Geometry.TYPENAME_LINEARRING: - return PolyGeometryType.LINEARRING; - case Geometry.TYPENAME_POLYGON: - return PolyGeometryType.POLYGON; - case Geometry.TYPENAME_GEOMETRYCOLLECTION: - return PolyGeometryType.GEOMETRYCOLLECTION; - case Geometry.TYPENAME_MULTIPOINT: - return PolyGeometryType.MULTIPOINT; - case Geometry.TYPENAME_MULTILINESTRING: - return PolyGeometryType.MULTILINESTRING; - case Geometry.TYPENAME_MULTIPOLYGON: - return PolyGeometryType.MULTIPOLYGON; - default: - throw new NotImplementedException( "value" ); - } + return switch ( jtsGeometry.getGeometryType() ) { + case Geometry.TYPENAME_POINT -> PolyGeometryType.POINT; + case Geometry.TYPENAME_LINESTRING -> PolyGeometryType.LINESTRING; + case Geometry.TYPENAME_LINEARRING -> PolyGeometryType.LINEARRING; + case Geometry.TYPENAME_POLYGON -> PolyGeometryType.POLYGON; + case Geometry.TYPENAME_GEOMETRYCOLLECTION -> PolyGeometryType.GEOMETRYCOLLECTION; + case Geometry.TYPENAME_MULTIPOINT -> PolyGeometryType.MULTIPOINT; + case Geometry.TYPENAME_MULTILINESTRING -> PolyGeometryType.MULTILINESTRING; + case Geometry.TYPENAME_MULTIPOLYGON -> PolyGeometryType.MULTIPOLYGON; + default -> throw new NotImplementedException( "value" ); + }; } @@ -845,10 +836,9 @@ public PolyGeometry symDifference( @NotNull PolyGeometry g ) throws GeometryTopo */ @Override public boolean equals( Object o ) { - if ( !(o instanceof PolyGeometry) ) { + if ( !(o instanceof PolyGeometry that) ) { return false; } - PolyGeometry that = (PolyGeometry) o; return geometryType.equals( that.geometryType ) && jtsGeometry.equals( that.jtsGeometry ) && Objects.equals( SRID, that.SRID ); } diff --git a/core/src/main/java/org/polypheny/db/util/BuiltInMethod.java b/core/src/main/java/org/polypheny/db/util/BuiltInMethod.java index 050a6b6fe6..4d6732f854 100644 --- a/core/src/main/java/org/polypheny/db/util/BuiltInMethod.java +++ b/core/src/main/java/org/polypheny/db/util/BuiltInMethod.java @@ -462,6 +462,7 @@ public enum BuiltInMethod { ST_REVERSE( GeoFunctions.class, "stReverse", PolyGeometry.class ), ST_BUFFER( GeoFunctions.class, "stBuffer", PolyGeometry.class, PolyNumber.class ), // Spatial relationships + ST_EQUALS( GeoFunctions.class, "stEquals", PolyGeometry.class, PolyGeometry.class ), ST_DWITHIN( GeoFunctions.class, "stDWithin", PolyGeometry.class, PolyGeometry.class, PolyNumber.class ), ST_DISJOINT( GeoFunctions.class, "stDisjoint", PolyGeometry.class, PolyGeometry.class ), ST_TOUCHES( GeoFunctions.class, "stTouches", PolyGeometry.class, PolyGeometry.class ), diff --git a/dbms/src/test/java/org/polypheny/db/sql/fun/GeoFunctionsTest.java b/dbms/src/test/java/org/polypheny/db/sql/fun/GeoFunctionsTest.java index 43ea4826fb..b7797f0de0 100644 --- a/dbms/src/test/java/org/polypheny/db/sql/fun/GeoFunctionsTest.java +++ b/dbms/src/test/java/org/polypheny/db/sql/fun/GeoFunctionsTest.java @@ -45,8 +45,6 @@ private static void addTestData() throws SQLException { try ( JdbcConnection jdbcConnection = new JdbcConnection( false ) ) { Connection connection = jdbcConnection.getConnection(); try ( Statement statement = connection.createStatement() ) { -// statement.executeUpdate( "CREATE TABLE TEST_GIS(ID INTEGER NOT NULL, WKT VARCHAR, PRIMARY KEY (ID))" ); -// statement.executeUpdate( "INSERT INTO TEST_GIS VALUES (1, SUBSTRING('POINT (7.852923 47.998949)', 1, 3))" ); statement.executeUpdate( "CREATE TABLE TEST_GIS(ID INTEGER NOT NULL, WKT GEOMETRY, PRIMARY KEY (ID))" ); statement.executeUpdate( "INSERT INTO TEST_GIS VALUES (1, ST_GeomFromText('POINT (7.852923 47.998949)', 4326))" ); statement.executeUpdate( "INSERT INTO TEST_GIS VALUES (2, ST_GeomFromText('POINT (9.289382 48.741588)', 4326))" ); @@ -236,6 +234,17 @@ public void spatialRelationsFunctions() throws SQLException { try ( TestHelper.JdbcConnection polyphenyDbConnection = new TestHelper.JdbcConnection( true ) ) { Connection connection = polyphenyDbConnection.getConnection(); try ( Statement statement = connection.createStatement() ) { + // check that two geo are equal + TestHelper.checkResultSet( + statement.executeQuery( "SELECT ST_Equals(ST_GeomFromText('POINT (7.852923 47.998949)', 4326), ST_GeomFromText('POINT (9.289382 48.741588)', 4326))" ), + ImmutableList.of( + new Object[]{ false } + ) ); + TestHelper.checkResultSet( + statement.executeQuery( "SELECT ST_Equals(ST_GeomFromText('POINT (7.852923 47.998949)', 4326), ST_GeomFromText('POINT (7.852923 47.998949)', 4326))" ), + ImmutableList.of( + new Object[]{ true } + ) ); // check that geo are within the distance TestHelper.checkResultSet( statement.executeQuery( "SELECT ST_DWithin(ST_GeomFromText('POINT (7.852923 47.998949)', 4326), ST_GeomFromText('POINT (9.289382 48.741588)', 4326), 135000)" ), diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java index 884e65807e..714b7dd68a 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/SqlLanguagePlugin.java @@ -2668,6 +2668,16 @@ public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec // Spatial relationships + register( + OperatorName.ST_EQUALS, + new SqlFunction( + "ST_EQUALS", + Kind.GEO, + ReturnTypes.BOOLEAN, + InferTypes.GEOMETRY, + OperandTypes.GEOMETRY_GEOMETRY, + FunctionCategory.GEOMETRY ) ); + register( OperatorName.ST_DWITHIN, new SqlFunction(