MARMOTTA-584: moved all geosparql functions to a new package
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/df172223 Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/df172223 Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/df172223 Branch: refs/heads/MARMOTTA-584 Commit: df172223edd9737aca591f49550714c71d2ea35a Parents: cdff84d Author: Sergio Fernández <[email protected]> Authored: Thu Sep 17 17:29:49 2015 +0200 Committer: Sergio Fernández <[email protected]> Committed: Thu Sep 17 17:29:49 2015 +0200 ---------------------------------------------------------------------- .../kiwi/sparql/geosparql/BoundaryFunction.java | 148 ----------------- .../kiwi/sparql/geosparql/BufferFunction.java | 156 ------------------ .../sparql/geosparql/ConvexHullFunction.java | 149 ----------------- .../sparql/geosparql/DifferenceFunction.java | 153 ------------------ .../kiwi/sparql/geosparql/DistanceFunction.java | 160 ------------------- .../sparql/geosparql/EhContainsFunction.java | 152 ------------------ .../sparql/geosparql/EhCoveredByFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/EhCoversFunction.java | 152 ------------------ .../sparql/geosparql/EhDisjointFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/EhEqualsFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/EhInsideFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/EhMeetFunction.java | 152 ------------------ .../sparql/geosparql/EhOverlapFunction.java | 153 ------------------ .../kiwi/sparql/geosparql/EnvelopeFunction.java | 148 ----------------- .../kiwi/sparql/geosparql/GetSRIDFunction.java | 136 ---------------- .../sparql/geosparql/IntersectionFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/Rcc8DCFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/Rcc8ECFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/Rcc8EQFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/Rcc8NTPPFunction.java | 152 ------------------ .../sparql/geosparql/Rcc8NTPPiFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/Rcc8POFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/Rcc8TPPFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/Rcc8TPPiFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/RelateFunction.java | 152 ------------------ .../sparql/geosparql/SfContainsFunction.java | 152 ------------------ .../sparql/geosparql/SfCrossesFunction.java | 152 ------------------ .../sparql/geosparql/SfDisjointFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/SfEqualsFunction.java | 152 ------------------ .../sparql/geosparql/SfIntersectsFunction.java | 152 ------------------ .../sparql/geosparql/SfOverlapsFunction.java | 152 ------------------ .../sparql/geosparql/SfTouchesFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/SfWithinFunction.java | 152 ------------------ .../sparql/geosparql/SymDifferenceFunction.java | 152 ------------------ .../kiwi/sparql/geosparql/UnionFunction.java | 152 ------------------ .../geosparql/functions/BoundaryFunction.java | 148 +++++++++++++++++ .../geosparql/functions/BufferFunction.java | 156 ++++++++++++++++++ .../geosparql/functions/ConvexHullFunction.java | 149 +++++++++++++++++ .../geosparql/functions/DifferenceFunction.java | 153 ++++++++++++++++++ .../geosparql/functions/DistanceFunction.java | 160 +++++++++++++++++++ .../geosparql/functions/EhContainsFunction.java | 152 ++++++++++++++++++ .../functions/EhCoveredByFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/EhCoversFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/EhDisjointFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/EhEqualsFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/EhInsideFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/EhMeetFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/EhOverlapFunction.java | 153 ++++++++++++++++++ .../geosparql/functions/EnvelopeFunction.java | 148 +++++++++++++++++ .../geosparql/functions/GetSRIDFunction.java | 136 ++++++++++++++++ .../functions/IntersectionFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/Rcc8DCFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/Rcc8ECFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/Rcc8EQFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/Rcc8NTPPFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/Rcc8NTPPiFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/Rcc8POFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/Rcc8TPPFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/Rcc8TPPiFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/RelateFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/SfContainsFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/SfCrossesFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/SfDisjointFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/SfEqualsFunction.java | 152 ++++++++++++++++++ .../functions/SfIntersectsFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/SfOverlapsFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/SfTouchesFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/SfWithinFunction.java | 152 ++++++++++++++++++ .../functions/SymDifferenceFunction.java | 152 ++++++++++++++++++ .../geosparql/functions/UnionFunction.java | 152 ++++++++++++++++++ ...marmotta.kiwi.sparql.function.NativeFunction | 70 ++++---- ...f.query.algebra.evaluation.function.Function | 70 ++++---- 72 files changed, 5377 insertions(+), 5377 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BoundaryFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BoundaryFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BoundaryFunction.java deleted file mode 100644 index e2f6874..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BoundaryFunction.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for doing a boundary of a geometry. Should be implemented - * directly in the database, as the in-memory implementation is non-functional. - * Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:boundary(?geometry) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class BoundaryFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.BOUNDARY.toString())) { - FunctionRegistry.getInstance().add(new BoundaryFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.BOUNDARY.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 1) { - String geom1 = args[0]; - String SRID_default = "4326"; - /* - * The following condition is required to read WKT inserted directly into args[0] and create a geometries with SRID - * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions: - * example: geof:buffer("POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral) - * st_AsText condition: It is to use the geometry that is the result of another function geosparql. - * example: geof:buffer(geof:convexhull(?geom)) - */ - if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) { - geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default); - } - return String.format("ST_AsText(ST_Boundary(%s)) ", geom1); - } - } - throw new UnsupportedOperationException("Boundary function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.GEOMETRY; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.GEOMETRY; - } - - /** - * Return the minimum number of arguments this function requires. - * - * @return - */ - @Override - public int getMinArgs() { - return 1; - } - - /** - * Return the maximum number of arguments this function can take - * - * @return - */ - @Override - public int getMaxArgs() { - return 1; - } -} http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BufferFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BufferFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BufferFunction.java deleted file mode 100644 index b5d69e4..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BufferFunction.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for doing a buffer of a geometry. Should be implemented - * directly in the database, as the in-memory implementation is non-functional. - * Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:buffer(?geometryA, radius, unit) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class BufferFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.BUFFER.toString())) { - FunctionRegistry.getInstance().add(new BufferFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.BUFFER.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 3) { - String geom1 = args[0]; - String SRID_default = "4326"; - /* - * The following condition is required to read WKT inserted directly into args[0] and create a geometries with SRID - * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions: - * example: geof:buffer("POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral) - * st_AsText condition: It is to use the geometry that is the result of another function geosparql. - * example: geof:buffer(geof:convexhull(?geom)) - */ - if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) { - geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default); - } - if (args[2].equalsIgnoreCase("'" + FN_GEOSPARQL.meter.toString() + "'") || args[2].equalsIgnoreCase("'" + FN_GEOSPARQL.metre.toString() + "'")) { - return String.format("ST_AsText(ST_Transform(ST_Buffer( ST_Transform( %s ,26986), %s),4326))", geom1, args[1]); - } - if (args[2].equalsIgnoreCase("'" + FN_GEOSPARQL.degree.toString() + "'")) { - return String.format("ST_AsText(ST_Buffer(%s, %s))", geom1, args[1]); - } - if (args[2].equalsIgnoreCase("'" + FN_GEOSPARQL.radian.toString() + "'")) { - return String.format("ST_AsText(ST_Buffer(%s, DEGREES(%s)))", geom1, args[1]); - } - } - } - throw new UnsupportedOperationException("Buffer function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.GEOMETRY; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.GEOMETRY; - } - - /** - * Return the minimum number of arguments this function requires. - * - * @return - */ - @Override - public int getMinArgs() { - return 3; - } - - /** - * Return the maximum number of arguments this function can take - * - * @return - */ - @Override - public int getMaxArgs() { - return 3; - } -} http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/ConvexHullFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/ConvexHullFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/ConvexHullFunction.java deleted file mode 100644 index c1fc8b8..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/ConvexHullFunction.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for doing a convexHull o a geometry. Should be implemented - * directly in the database, as the in-memory implementation is non-functional. - * Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:convexHull(?geometryA) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class ConvexHullFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.CONVEX_HULL.toString())) { - FunctionRegistry.getInstance().add(new ConvexHullFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.CONVEX_HULL.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 1) { - String geom1 = args[0]; - String SRID_default = "4326"; - /* - * The following condition is required to read WKT inserted directly into args[0] and create a geometries with SRID - * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions: - * example: geof:convexHull("POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral) - * st_AsText condition: It is to use the geometry that is the result of another function geosparql. - * example: geof:convexHull(geof:buffer(?geom, 50, units:meter)) - */ - if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) { - geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default); - } - return String.format("ST_AsText(st_convexHull(%s))", geom1); - } - } - throw new UnsupportedOperationException("ConvexHull function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.GEOMETRY; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg - ) { - return ValueType.GEOMETRY; - } - - /** - * Return the minimum number of arguments this function requires. - * - * @return - */ - @Override - public int getMinArgs() { - return 1; - } - - /** - * Return the maximum number of arguments this function can take - * - * @return - */ - @Override - public int getMaxArgs() { - return 1; - } -} http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DifferenceFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DifferenceFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DifferenceFunction.java deleted file mode 100644 index 58cd73d..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DifferenceFunction.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for doing a difference of a geometry. Should be implemented - * directly in the database, as the in-memory implementation is non-functional. - * Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:difference(?geometryA, ?geometryB) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class DifferenceFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.DIFFERENCE.toString())) { - FunctionRegistry.getInstance().add(new DifferenceFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.DIFFERENCE.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - String geom1 = args[0]; - String geom2 = args[1]; - String SRID_default = "4326"; - /* - * The following condition is required to read WKT inserted directly into args[0] or args[1] and create a geometries with SRID - * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions: - * example: geof:difference(?geom1, "POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral) - * st_AsText condition: It is to use the geometry that is the result of another function geosparql. - * example: geof:difference(?geom1, geof:buffer(?geometry, 50, units:meter)) - */ - if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) { - geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default); - } - if (args[1].contains("POINT") || args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) { - geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], SRID_default); - } - return String.format("ST_AsText(ST_Difference(%s , %s )) ", geom1, geom2); - } - } - throw new UnsupportedOperationException("Difference function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.GEOMETRY; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg - ) { - return ValueType.GEOMETRY; - } - - /** - * Return the minimum number of arguments this function requires. - * - * @return - */ - @Override - public int getMinArgs() { - return 2; - } - - /** - * Return the maximum number of arguments this function can take - * - * @return - */ - @Override - public int getMaxArgs() { - return 2; - } -} http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DistanceFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DistanceFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DistanceFunction.java deleted file mode 100644 index 8a618be..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DistanceFunction.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * Returns the shortest distance in units between any two Points of two - * geometries. Should be implemented directly in the database, as the in-memory - * implementation is non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:distance(?geometryA, ?geometryB, units:meter) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class DistanceFunction implements NativeFunction { -// auto-register for SPARQL environment - - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.DISTANCE.toString())) { - FunctionRegistry.getInstance().add(new DistanceFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.DISTANCE.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 3) { - String geom1 = args[0]; - String geom2 = args[1]; - String SRID_default = "4326"; - /* - * The following condition is required to read WKT inserted directly into args[0] or args[1] and create a geometries with SRID - * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions: - * example: geof:distance(?geom1, "POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral) - * st_AsText condition: It is to use the geometry that is the result of another function geosparql. - * example: geof:distance(?geom1, geof:buffer(?geom2, 50, units:meter)) - */ - if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) { - geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default); - } - if (args[1].contains("POINT") || args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) { - geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], SRID_default); - } - if (args[2].equalsIgnoreCase("'" + FN_GEOSPARQL.meter.toString() + "'") || args[2].equalsIgnoreCase("'" + FN_GEOSPARQL.metre.toString() + "'")) { - return String.format("ST_Distance( ST_Transform( %s ,26986), ST_Transform( %s ,26986))", geom1, geom2); - } - if (args[2].equalsIgnoreCase("'" + FN_GEOSPARQL.degree.toString() + "'")) { - return String.format("ST_Distance(%s, %s)", geom1, geom2); - } - if (args[2].equalsIgnoreCase("'" + FN_GEOSPARQL.radian.toString() + "'")) { - return String.format("RADIANS(ST_Distance(%s, %s))", geom1, geom2); - } - } - } - throw new UnsupportedOperationException("Distance function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.DOUBLE; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.GEOMETRY; - } - - /** - * Return the minimum number of arguments this function requires. - * - * @return - */ - @Override - public int getMinArgs() { - return 3; - } - - /** - * Return the maximum number of arguments this function can take - * - * @return - */ - @Override - public int getMaxArgs() { - return 3; - } -} http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhContainsFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhContainsFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhContainsFunction.java deleted file mode 100644 index 8bf7581..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhContainsFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for analyze the Contains Relate between two geometries. - * Should be implemented directly in the database, as the in-memory - * implementation is non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:ehContains(?geometryA, ?geometryB) </li> - * </ul> - * Contains Relate is calculated with "DE-9IM Intersection Pattern": defined in - * "RCC8 Query Functions Table 6" from "DE-9IM Intersection Pattern" from OGC - * GEOSPARQL DOCUMENT ( - * https://portal.opengeospatial.org/files/?artifact_id=47664 ) - * - * @author Xavier Sumba ([email protected])) - */ -public class EhContainsFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_CONTAINS.toString())) { - FunctionRegistry.getInstance().add(new EhContainsFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.EH_CONTAINS.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - String geom1 = args[0]; - String geom2 = args[1]; - String SRID_default = "4326"; - /* - * The following condition is required to read WKT inserted directly into args[0] or args[1] and create a geometries with SRID - * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions: - * example: geof:ehContains(?geom1, "POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral) - * st_AsText condition: It is to use the geometry that is the result of another function geosparql. - * example: geof:ehContains(?geom1, geof:buffer(?geom2, 50, units:meter)) - */ - if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) { - geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default); - } - if (args[1].contains("POINT") || args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) { - geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], SRID_default); - } - return String.format("ST_Relate(%s, %s, 'T*TFF*FF*')", geom1, geom2); - } - } - throw new UnsupportedOperationException("ehContains function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.BOOL; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.GEOMETRY; - } - - /** - * Return the minimum number of arguments this function requires. - * - * @return - */ - @Override - public int getMinArgs() { - return 2; - } - - /** - * Return the maximum number of arguments this function can take - * - * @return - */ - @Override - public int getMaxArgs() { - return 2; - } -} http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoveredByFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoveredByFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoveredByFunction.java deleted file mode 100644 index b652497..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoveredByFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for analyze the CoveredBy Relate between two geometries. - * Should be implemented directly in the database, as the in-memory - * implementation is non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:ehCoveredBy(?geometryA, ?geometryB) </li> - * </ul> - * CoveredBy Relate is calculated with "DE-9IM Intersection Pattern": defined in - * "RCC8 Query Functions Table 7" from "DE-9IM Intersection Pattern" from OGC - * GEOSPARQL DOCUMENT ( - * https://portal.opengeospatial.org/files/?artifact_id=47664 ) - * - * @author Xavier Sumba ([email protected])) - */ -public class EhCoveredByFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_COVEREDBY.toString())) { - FunctionRegistry.getInstance().add(new EhCoveredByFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.EH_COVEREDBY.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - String geom1 = args[0]; - String geom2 = args[1]; - String SRID_default = "4326"; - /* - * The following condition is required to read WKT inserted directly into args[0] or args[1] and create a geometries with SRID - * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions: - * example: geof:ehCoveredBy(?geom1, "POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral) - * st_AsText condition: It is to use the geometry that is the result of another function geosparql. - * example: geof:ehCoveredBy(?geom1, geof:buffer(?geom2, 50, units:meter)) - */ - if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) { - geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default); - } - if (args[1].contains("POINT") || args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) { - geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], SRID_default); - } - return String.format("ST_Relate(%s, %s, 'TFF*TFT**')", geom1, geom2); - } - } - throw new UnsupportedOperationException("ehCoveredBy function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.BOOL; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.GEOMETRY; - } - - /** - * Return the minimum number of arguments this function requires. - * - * @return - */ - @Override - public int getMinArgs() { - return 2; - } - - /** - * Return the maximum number of arguments this function can take - * - * @return - */ - @Override - public int getMaxArgs() { - return 2; - } -} http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoversFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoversFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoversFunction.java deleted file mode 100644 index 8b13e33..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoversFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for analyze the Covers Relate between two geometries. - * Should be implemented directly in the database, as the in-memory - * implementation is non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:ehCovers(?geometryA, ?geometryB) </li> - * </ul> - * Covers Relate is calculated with "DE-9IM Intersection Pattern": defined in - * "RCC8 Query Functions Table 6" from "DE-9IM Intersection Pattern" from OGC - * GEOSPARQL DOCUMENT ( - * https://portal.opengeospatial.org/files/?artifact_id=47664 ) - * - * @author Xavier Sumba ([email protected])) - */ -public class EhCoversFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_COVERS.toString())) { - FunctionRegistry.getInstance().add(new EhCoversFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.EH_COVERS.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - String geom1 = args[0]; - String geom2 = args[1]; - String SRID_default = "4326"; - /* - * The following condition is required to read WKT inserted directly into args[0] or args[1] and create a geometries with SRID - * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions: - * example: geof:ehCovers(?geom1, "POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral) - * st_AsText condition: It is to use the geometry that is the result of another function geosparql. - * example: geof:ehCovers(?geom1, geof:buffer(?geom2, 50, units:meter)) - */ - if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) { - geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default); - } - if (args[1].contains("POINT") || args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) { - geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], SRID_default); - } - return String.format("ST_Relate(%s, %s, 'T*TFT*FF*')", geom1, geom2); - } - } - throw new UnsupportedOperationException("ehCovers function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.BOOL; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.GEOMETRY; - } - - /** - * Return the minimum number of arguments this function requires. - * - * @return - */ - @Override - public int getMinArgs() { - return 2; - } - - /** - * Return the maximum number of arguments this function can take - * - * @return - */ - @Override - public int getMaxArgs() { - return 2; - } -} http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhDisjointFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhDisjointFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhDisjointFunction.java deleted file mode 100644 index 05bb954..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhDisjointFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for analyze the Disjoint between two geometries. Should be - * implemented directly in the database, as the in-memory implementation is - * non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:ehDisjoint(?geometryA, ?geometryB) </li> - * </ul> - * Disjoint is calculated with "DE-9IM Intersection Pattern": defined in "RCC8 - * Query Functions Table 6" from "DE-9IM Intersection Pattern" from OGC - * GEOSPARQL DOCUMENT ( - * https://portal.opengeospatial.org/files/?artifact_id=47664 ) - * - * @author Xavier Sumba ([email protected])) - */ -public class EhDisjointFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_DISJOINT.toString())) { - FunctionRegistry.getInstance().add(new EhDisjointFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.EH_DISJOINT.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - String geom1 = args[0]; - String geom2 = args[1]; - String SRID_default = "4326"; - /* - * The following condition is required to read WKT inserted directly into args[0] or args[1] and create a geometries with SRID - * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions: - * example: geof:ehDisjoint(?geom1, "POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral) - * st_AsText condition: It is to use the geometry that is the result of another function geosparql. - * example: geof:ehDisjoint(?geom1, geof:buffer(?geom2, 50, units:meter)) - */ - if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) { - geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default); - } - if (args[1].contains("POINT") || args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) { - geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], SRID_default); - } - return String.format("ST_Relate(%s, %s, 'FF*FF****')", geom1, geom2); - } - } - throw new UnsupportedOperationException("ehDisjoint function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.BOOL; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.GEOMETRY; - } - - /** - * Return the minimum number of arguments this function requires. - * - * @return - */ - @Override - public int getMinArgs() { - return 2; - } - - /** - * Return the maximum number of arguments this function can take - * - * @return - */ - @Override - public int getMaxArgs() { - return 2; - } -} http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhEqualsFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhEqualsFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhEqualsFunction.java deleted file mode 100644 index 515f7c3..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhEqualsFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for analyze the EhEquals between two geometries. Should be - * implemented directly in the database, as the in-memory implementation is - * non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:ehEquals(?geometryA, ?geometryB) </li> - * </ul> - * EhEquals is calculated with "DE-9IM Intersection Pattern": defined in "RCC8 - * Query Functions Table 6" from "DE-9IM Intersection Pattern" from OGC - * GEOSPARQL DOCUMENT ( - * https://portal.opengeospatial.org/files/?artifact_id=47664 ) - * - * @author Xavier Sumba ([email protected])) - */ -public class EhEqualsFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_EQUALS.toString())) { - FunctionRegistry.getInstance().add(new EhEqualsFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.EH_EQUALS.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - String geom1 = args[0]; - String geom2 = args[1]; - String SRID_default = "4326"; - /* - * The following condition is required to read WKT inserted directly into args[0] or args[1] and create a geometries with SRID - * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions: - * example: geof:ehEquals(?geom1, "POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral) - * st_AsText condition: It is to use the geometry that is the result of another function geosparql. - * example: geof:ehEquals(?geom1, geof:buffer(?geom2, 50, units:meter)) - */ - if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) { - geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default); - } - if (args[1].contains("POINT") || args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) { - geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], SRID_default); - } - return String.format("ST_Relate(%s, %s, 'TFFFTFFFT')", geom1, geom2); - } - } - throw new UnsupportedOperationException("ehEquals function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.BOOL; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.GEOMETRY; - } - - /** - * Return the minimum number of arguments this function requires. - * - * @return - */ - @Override - public int getMinArgs() { - return 2; - } - - /** - * Return the maximum number of arguments this function can take - * - * @return - */ - @Override - public int getMaxArgs() { - return 2; - } -} http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhInsideFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhInsideFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhInsideFunction.java deleted file mode 100644 index 0ca7c11..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhInsideFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for analyze the Inside Relate between two geometries. - * Should be implemented directly in the database, as the in-memory - * implementation is non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:ehInside(?geometryA, ?geometryB) </li> - * </ul> - * Inside Relate is calculated with "DE-9IM Intersection Pattern": defined in - * "RCC8 Query Functions Table 6" from "DE-9IM Intersection Pattern" from OGC - * GEOSPARQL DOCUMENT ( - * https://portal.opengeospatial.org/files/?artifact_id=47664 ) - * - * @author Xavier Sumba ([email protected])) - */ -public class EhInsideFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_INSIDE.toString())) { - FunctionRegistry.getInstance().add(new EhInsideFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.EH_INSIDE.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - String geom1 = args[0]; - String geom2 = args[1]; - String SRID_default = "4326"; - /* - * The following condition is required to read WKT inserted directly into args[0] or args[1] and create a geometries with SRID - * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions: - * example: geof:ehInside(?geom, "POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral) - * st_AsText condition: It is to use the geometry that is the result of another function geosparql. - * example: geof:ehInside(?geom, geof:buffer(?geom2, 50, units:meter)) - */ - if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) { - geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default); - } - if (args[1].contains("POINT") || args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) { - geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], SRID_default); - } - return String.format("ST_Relate(%s, %s, 'TFF*FFT**')", geom1, geom2); - } - } - throw new UnsupportedOperationException("ehInside function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.BOOL; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.GEOMETRY; - } - - /** - * Return the minimum number of arguments this function requires. - * - * @return - */ - @Override - public int getMinArgs() { - return 2; - } - - /** - * Return the maximum number of arguments this function can take - * - * @return - */ - @Override - public int getMaxArgs() { - return 2; - } -} http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhMeetFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhMeetFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhMeetFunction.java deleted file mode 100644 index 86690de..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhMeetFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for analyze the Meet Relate between two geometries. Should - * be implemented directly in the database, as the in-memory implementation is - * non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:ehMeet(?geometryA, ?geometryB) </li> - * </ul> - * Meet Relate is calculated with "DE-9IM Intersection Pattern": defined in - * "RCC8 Query Functions Table 6" from "DE-9IM Intersection Pattern" from OGC - * GEOSPARQL DOCUMENT ( - * https://portal.opengeospatial.org/files/?artifact_id=47664 ) - * - * @author Xavier Sumba ([email protected])) - */ -public class EhMeetFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_MEET.toString())) { - FunctionRegistry.getInstance().add(new EhMeetFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.EH_MEET.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - String geom1 = args[0]; - String geom2 = args[1]; - String SRID_default = "4326"; - /* - * The following condition is required to read WKT inserted directly into args[0] or args[1] and create a geometries with SRID - * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions: - * example: geof:ehMeet(?geom1, "POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral) - * st_AsText condition: It is to use the geometry that is the result of another function geosparql. - * example: geof:ehMeet(?geom1, geof:buffer(?geom2, 50, units:meter)) - */ - if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) { - geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default); - } - if (args[1].contains("POINT") || args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) { - geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], SRID_default); - } - return String.format("ST_Relate(%s, %s, 'F***T****')", geom1, geom2); - } - } - throw new UnsupportedOperationException("ehMeet function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.BOOL; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.GEOMETRY; - } - - /** - * Return the minimum number of arguments this function requires. - * - * @return - */ - @Override - public int getMinArgs() { - return 2; - } - - /** - * Return the maximum number of arguments this function can take - * - * @return - */ - @Override - public int getMaxArgs() { - return 2; - } -}
