Implemented Functions: Boundary Difference Distance Envelope Relate SymDifference Union
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/0acf49b4 Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/0acf49b4 Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/0acf49b4 Branch: refs/heads/MARMOTTA-584 Commit: 0acf49b46f8d7b754d0ec6bb9e0a95e8dba567d5 Parents: d46029a Author: cuent <[email protected]> Authored: Mon Aug 10 18:50:16 2015 -0500 Committer: cuent <[email protected]> Committed: Mon Aug 10 18:50:16 2015 -0500 ---------------------------------------------------------------------- .../function/geosparql/BoundaryFunction.java | 140 +++++++++++++++++++ .../function/geosparql/BufferFunction.java | 50 +++---- .../function/geosparql/ConvexHullFunction.java | 48 ++++--- .../function/geosparql/DifferenceFunction.java | 140 +++++++++++++++++++ .../function/geosparql/DistanceFunction.java | 140 +++++++++++++++++++ .../function/geosparql/EnvelopeFunction.java | 140 +++++++++++++++++++ .../geosparql/IntersectionFunction.java | 51 ++++--- .../function/geosparql/RelateFunction.java | 140 +++++++++++++++++++ .../function/geosparql/SfContainsFunction.java | 6 +- .../function/geosparql/SfCrossesFunction.java | 50 +++---- .../function/geosparql/SfDisjointFunction.java | 50 +++---- .../function/geosparql/SfEqualsFunction.java | 50 +++---- .../geosparql/SfIntersectsFunction.java | 51 +++---- .../function/geosparql/SfOverlapsFunction.java | 51 +++---- .../function/geosparql/SfTouchesFunction.java | 53 +++---- .../geosparql/SymDifferenceFunction.java | 139 ++++++++++++++++++ .../function/geosparql/UnionFunction.java | 140 +++++++++++++++++++ ...marmotta.kiwi.sparql.function.NativeFunction | 7 + ...f.query.algebra.evaluation.function.Function | 7 + .../marmotta/kiwi/vocabulary/FN_GEOSPARQL.java | 39 ++++-- 20 files changed, 1261 insertions(+), 231 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/BoundaryFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/BoundaryFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/BoundaryFunction.java new file mode 100644 index 0000000..68c8c75 --- /dev/null +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/BoundaryFunction.java @@ -0,0 +1,140 @@ +/* + * 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.function.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 == 2) { + if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry + return String.format("ST_AsText(ST_Boundary(%s))", args[0]); + } + return String.format("ST_AsText(ST_Boundary(%s)) ", args[0]); + } + + } + 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/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/BufferFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/BufferFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/BufferFunction.java index fa3901a..1214d58 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/BufferFunction.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/BufferFunction.java @@ -16,7 +16,6 @@ */ package org.apache.marmotta.kiwi.sparql.function.geosparql; - import org.apache.marmotta.kiwi.persistence.KiWiDialect; import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; import org.apache.marmotta.kiwi.sparql.builder.ValueType; @@ -28,24 +27,26 @@ 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 + * 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) </li> + * <li>geof:buffer(?geometryA, radius) </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. + * 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 Zumba ([email protected])) + * @author Xavier Sumba ([email protected])) */ public class BufferFunction implements NativeFunction { // auto-register for SPARQL environment static { - if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.BUFFER.toString())) { + if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.BUFFER.toString())) { FunctionRegistry.getInstance().add(new BufferFunction()); } } @@ -60,9 +61,9 @@ public class BufferFunction implements NativeFunction { return FN_GEOSPARQL.BUFFER.toString(); } - /** - * Return true if this function has available native support for the given dialect + * Return true if this function has available native support for the given + * dialect * * @param dialect * @return @@ -73,7 +74,8 @@ public class BufferFunction implements NativeFunction { } /** - * Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect + * Return a string representing how this GeoSPARQL function is translated + * into SQL ( Postgis Function ) in the given dialect * * @param dialect * @param args @@ -81,21 +83,21 @@ public class BufferFunction implements NativeFunction { */ @Override public String getNative(KiWiDialect dialect, String... args) { - if(dialect instanceof PostgreSQLDialect) { - if(args.length == 2) { - if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON)|| args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) - { //If users insert Direct the WKT Geometry - return "ST_AsText(st_Buffer("+args[0] + " , " + args[1] + " ))"; - } - return "ST_AsText(st_Buffer("+args[0] + " , " + args[1] + " )) "; - } + if (dialect instanceof PostgreSQLDialect) { + if (args.length == 2) { + if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry + return String.format("ST_AsText(st_Buffer(%s , %s ))", args[0], args[1]); + } + return String.format("ST_AsText(st_Buffer(%s , %s )) ", args[0], args[1]); + } } - throw new UnsupportedOperationException("buffer function not supported by dialect "+dialect); + 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. + * Get the return type of the function. This is needed for SQL type casting + * inside KiWi. * * @return */ @@ -105,8 +107,8 @@ public class BufferFunction implements NativeFunction { } /** - * 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. + * 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 http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/ConvexHullFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/ConvexHullFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/ConvexHullFunction.java index 89973d5..63ae16f 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/ConvexHullFunction.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/ConvexHullFunction.java @@ -16,7 +16,6 @@ */ package org.apache.marmotta.kiwi.sparql.function.geosparql; - import org.apache.marmotta.kiwi.persistence.KiWiDialect; import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; import org.apache.marmotta.kiwi.sparql.builder.ValueType; @@ -28,16 +27,18 @@ 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 + * 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> + * <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. + * 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])) */ @@ -45,7 +46,7 @@ public class ConvexHullFunction implements NativeFunction { // auto-register for SPARQL environment static { - if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.CONVEX_HULL.toString())) { + if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.CONVEX_HULL.toString())) { FunctionRegistry.getInstance().add(new ConvexHullFunction()); } } @@ -60,9 +61,9 @@ public class ConvexHullFunction implements NativeFunction { return FN_GEOSPARQL.CONVEX_HULL.toString(); } - /** - * Return true if this function has available native support for the given dialect + * Return true if this function has available native support for the given + * dialect * * @param dialect * @return @@ -73,7 +74,8 @@ public class ConvexHullFunction implements NativeFunction { } /** - * Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect + * Return a string representing how this GeoSPARQL function is translated + * into SQL ( Postgis Function ) in the given dialect * * @param dialect * @param args @@ -81,21 +83,21 @@ public class ConvexHullFunction implements NativeFunction { */ @Override public String getNative(KiWiDialect dialect, String... args) { - if(dialect instanceof PostgreSQLDialect) { - if(args.length == 1) { - if (args[0].contains(FN_GEOSPARQL.MULTIPOLYGON)|| args[0].contains(FN_GEOSPARQL.MULTILINESTRING) || args[0].contains(FN_GEOSPARQL.POINT)) - { //If users insert Direct the WKT Geometry - return "ST_AsText(st_convexHull( " + args[0] + " ))"; - } - return "ST_AsText(st_convexHull(" + args[0] +"))"; - } + if (dialect instanceof PostgreSQLDialect) { + if (args.length == 1) { + if (args[0].contains(FN_GEOSPARQL.MULTIPOLYGON) || args[0].contains(FN_GEOSPARQL.MULTILINESTRING) || args[0].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry + return String.format("ST_AsText(st_convexHull( %s ))", args[0]); + } + return String.format("ST_AsText(st_convexHull(%s))", args[0]); + } } - throw new UnsupportedOperationException("convexHull function not supported by dialect "+dialect); + 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. + * Get the return type of the function. This is needed for SQL type casting + * inside KiWi. * * @return */ @@ -105,8 +107,8 @@ public class ConvexHullFunction implements NativeFunction { } /** - * 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. + * 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 http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/DifferenceFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/DifferenceFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/DifferenceFunction.java new file mode 100644 index 0000000..111cff9 --- /dev/null +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/DifferenceFunction.java @@ -0,0 +1,140 @@ +/* + * 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.function.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) { + if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry + return String.format("ST_AsText(ST_Difference(%s , %s ))", args[0], args[1]); + } + return String.format("ST_AsText(ST_Difference(%s , %s )) ", args[0], args[1]); + } + + } + 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/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/DistanceFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/DistanceFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/DistanceFunction.java new file mode 100644 index 0000000..2f25736 --- /dev/null +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/DistanceFunction.java @@ -0,0 +1,140 @@ +/* + * 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.function.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) { + if (args[2].equalsIgnoreCase("'" + FN_GEOSPARQL.meter.toString() + "'")) { + return "ST_Distance( ST_Transform( " + args[0] + " ,26986), ST_Transform( " + args[1] + " ,26986))"; + + } + } + + } + 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 2; + } + + /** + * 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/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/EnvelopeFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/EnvelopeFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/EnvelopeFunction.java new file mode 100644 index 0000000..0365a44 --- /dev/null +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/EnvelopeFunction.java @@ -0,0 +1,140 @@ +/* + * 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.function.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 an envelope 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:envelope(?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 EnvelopeFunction implements NativeFunction { + + // auto-register for SPARQL environment + static { + if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.ENVELOPE.toString())) { + FunctionRegistry.getInstance().add(new EnvelopeFunction()); + } + } + + @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.ENVELOPE.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) { + if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry + return String.format("ST_AsText(ST_Envelope(%s))", args[0]); + } + return String.format("ST_AsText(ST_Envelope(%s)) ", args[0]); + } + + } + throw new UnsupportedOperationException("Envelope 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/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/IntersectionFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/IntersectionFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/IntersectionFunction.java index 790d1da..a899a51 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/IntersectionFunction.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/IntersectionFunction.java @@ -16,7 +16,6 @@ */ package org.apache.marmotta.kiwi.sparql.function.geosparql; - import org.apache.marmotta.kiwi.persistence.KiWiDialect; import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; import org.apache.marmotta.kiwi.sparql.builder.ValueType; @@ -28,16 +27,18 @@ import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; /** - * A SPARQL function for doing a intersection between two geometries. Should be implemented directly in - * the database, as the in-memory implementation is non-functional. Only support by postgres - POSTGIS + * A SPARQL function for doing a intersection 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:intersection(?geometryA, ?geometryB) </li> + * <li>geof:intersection(?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. + * 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])) */ @@ -45,7 +46,7 @@ public class IntersectionFunction implements NativeFunction { // auto-register for SPARQL environment static { - if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.INTERSECTION.toString())) { + if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.INTERSECTION.toString())) { FunctionRegistry.getInstance().add(new IntersectionFunction()); } } @@ -60,9 +61,9 @@ public class IntersectionFunction implements NativeFunction { return FN_GEOSPARQL.INTERSECTION.toString(); } - /** - * Return true if this function has available native support for the given dialect + * Return true if this function has available native support for the given + * dialect * * @param dialect * @return @@ -73,7 +74,8 @@ public class IntersectionFunction implements NativeFunction { } /** - * Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect + * Return a string representing how this GeoSPARQL function is translated + * into SQL ( Postgis Function ) in the given dialect * * @param dialect * @param args @@ -81,25 +83,22 @@ public class IntersectionFunction implements NativeFunction { */ @Override public String getNative(KiWiDialect dialect, String... args) { - if(dialect instanceof PostgreSQLDialect) { + if (dialect instanceof PostgreSQLDialect) { - if(args.length == 2) { - if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON)|| args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) - { //If users insert Direct the WKT Geometry - return "ST_AsText(st_Intersection(" + args[0] + " , " + args[1] + " ) )"; - } - return "ST_AsText(st_Intersection(" + args[0] + " , " + args[1] + " ) )"; - } + if (args.length == 2) { + if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry + return String.format("ST_AsText(st_Intersection(%s , %s ) )", args[0], args[1]); + } + return String.format("ST_AsText(st_Intersection(%s , %s ) )", args[0], args[1]); + } - - - } - throw new UnsupportedOperationException("intersection function not supported by dialect "+dialect); + throw new UnsupportedOperationException("intersection function not supported by dialect " + dialect); } /** - * Get the return type of the function. This is needed for SQL type casting inside KiWi. + * Get the return type of the function. This is needed for SQL type casting + * inside KiWi. * * @return */ @@ -109,8 +108,8 @@ public class IntersectionFunction implements NativeFunction { } /** - * 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. + * 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 http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/RelateFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/RelateFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/RelateFunction.java new file mode 100644 index 0000000..db63d2b --- /dev/null +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/RelateFunction.java @@ -0,0 +1,140 @@ +/* + * 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.function.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 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:relate (?geom1, ?geom2, ?pattern-matrix)</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 RelateFunction implements NativeFunction { + + // auto-register for SPARQL environment + static { + if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.RELATE.toString())) { + FunctionRegistry.getInstance().add(new RelateFunction()); + } + } + + @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.RELATE.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) { + if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry + return String.format("ST_Relate(%s, %s, %s )", args[0], args[1], args[2]); + } + return String.format("ST_Relate(%s, %s , %s)", args[0], args[1], args[2]); + } + + } + throw new UnsupportedOperationException("Relate 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 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/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfContainsFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfContainsFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfContainsFunction.java index a7df54f..95dd9a7 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfContainsFunction.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfContainsFunction.java @@ -39,7 +39,7 @@ import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; * 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 Zumba ([email protected])) + * @author Xavier Sumba ([email protected])) */ public class SfContainsFunction implements NativeFunction { @@ -85,9 +85,9 @@ public class SfContainsFunction implements NativeFunction { if(args.length == 2) { if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON)|| args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry - return "st_Contains(" + args[0] + " , " + args[1] + " )"; + return String.format("st_Contains(%s , %s )",args[0],args[1]); } - return "st_Contains(" + args[0] + " , " + args[1] + " )"; + return String.format("st_Contains(%s , %s )",args[0],args[1]); } } http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfCrossesFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfCrossesFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfCrossesFunction.java index 2dbe7f3..48708ea 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfCrossesFunction.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfCrossesFunction.java @@ -16,7 +16,6 @@ */ package org.apache.marmotta.kiwi.sparql.function.geosparql; - import org.apache.marmotta.kiwi.persistence.KiWiDialect; import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; import org.apache.marmotta.kiwi.sparql.builder.ValueType; @@ -28,24 +27,26 @@ import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; /** - * A SPARQL function for doing a crosses between two geometries. Should be implemented directly in - * the database, as the in-memory implementation is non-functional. Only support by postgres - POSTGIS + * A SPARQL function for doing a crosses 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:sfCrosses(?geometryA, ?geometryB) </li> + * <li>geof:sfCrosses(?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. + * 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 Zumba ([email protected])) + * @author Xavier Sumba ([email protected])) */ public class SfCrossesFunction implements NativeFunction { // auto-register for SPARQL environment static { - if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_CROSSES.toString())) { + if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_CROSSES.toString())) { FunctionRegistry.getInstance().add(new SfCrossesFunction()); } } @@ -60,9 +61,9 @@ public class SfCrossesFunction implements NativeFunction { return FN_GEOSPARQL.SF_CROSSES.toString(); } - /** - * Return true if this function has available native support for the given dialect + * Return true if this function has available native support for the given + * dialect * * @param dialect * @return @@ -73,7 +74,8 @@ public class SfCrossesFunction implements NativeFunction { } /** - * Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect + * Return a string representing how this GeoSPARQL function is translated + * into SQL ( Postgis Function ) in the given dialect * * @param dialect * @param args @@ -81,21 +83,21 @@ public class SfCrossesFunction implements NativeFunction { */ @Override public String getNative(KiWiDialect dialect, String... args) { - if(dialect instanceof PostgreSQLDialect) { - if(args.length == 2) { - if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON)|| args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) - { //If users insert Direct the WKT Geometry - return "st_Crosses(" + args[0] + " , " + args[1] + " )"; - } - return "st_Crosses(" + args[0] + " , " + args[1] + " )"; - } + if (dialect instanceof PostgreSQLDialect) { + if (args.length == 2) { + if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry + return String.format("st_Crosses(%s , %s )", args[0], args[1]); + } + return String.format("st_Crosses(%s , %s )", args[0], args[1]); + } } - throw new UnsupportedOperationException("sfCrosses function not supported by dialect "+dialect); + throw new UnsupportedOperationException("sfCrosses function not supported by dialect " + dialect); } /** - * Get the return type of the function. This is needed for SQL type casting inside KiWi. + * Get the return type of the function. This is needed for SQL type casting + * inside KiWi. * * @return */ @@ -105,8 +107,8 @@ public class SfCrossesFunction implements NativeFunction { } /** - * 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. + * 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 http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfDisjointFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfDisjointFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfDisjointFunction.java index 9651ee1..79f430f 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfDisjointFunction.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfDisjointFunction.java @@ -16,7 +16,6 @@ */ package org.apache.marmotta.kiwi.sparql.function.geosparql; - import org.apache.marmotta.kiwi.persistence.KiWiDialect; import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; import org.apache.marmotta.kiwi.sparql.builder.ValueType; @@ -28,24 +27,26 @@ import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; /** - * A SPARQL function for doing a Disjoint between two geometries. Should be implemented directly in - * the database, as the in-memory implementation is non-functional. Only support by postgres - POSTGIS + * A SPARQL function for doing a 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:sfDisjoint(?geometryA, ?geometryB) </li> + * <li>geof:sfDisjoint(?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. + * 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 Zumba ([email protected])) + * @author Xavier Sumba ([email protected])) */ public class SfDisjointFunction implements NativeFunction { // auto-register for SPARQL environment static { - if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_DISJOINT.toString())) { + if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_DISJOINT.toString())) { FunctionRegistry.getInstance().add(new SfDisjointFunction()); } } @@ -60,9 +61,9 @@ public class SfDisjointFunction implements NativeFunction { return FN_GEOSPARQL.SF_DISJOINT.toString(); } - /** - * Return true if this function has available native support for the given dialect + * Return true if this function has available native support for the given + * dialect * * @param dialect * @return @@ -73,7 +74,8 @@ public class SfDisjointFunction implements NativeFunction { } /** - * Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect + * Return a string representing how this GeoSPARQL function is translated + * into SQL ( Postgis Function ) in the given dialect * * @param dialect * @param args @@ -81,21 +83,21 @@ public class SfDisjointFunction implements NativeFunction { */ @Override public String getNative(KiWiDialect dialect, String... args) { - if(dialect instanceof PostgreSQLDialect) { - if(args.length == 2) { - if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON)|| args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) - { //If users insert Direct the WKT Geometry - return "st_Disjoint(" + args[0] + " , " + args[1] + " )"; - } - return "st_Disjoint(" + args[0] + " , " + args[1] + " )"; - } + if (dialect instanceof PostgreSQLDialect) { + if (args.length == 2) { + if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry + return String.format("st_Disjoint(%s , %s )", args[0], args[1]); + } + return String.format("st_Disjoint(%s , %s )", args[0], args[1]); + } } - throw new UnsupportedOperationException("sfDisjoint function not supported by dialect "+dialect); + throw new UnsupportedOperationException("sfDisjoint function not supported by dialect " + dialect); } /** - * Get the return type of the function. This is needed for SQL type casting inside KiWi. + * Get the return type of the function. This is needed for SQL type casting + * inside KiWi. * * @return */ @@ -105,8 +107,8 @@ public class SfDisjointFunction implements NativeFunction { } /** - * 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. + * 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 http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfEqualsFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfEqualsFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfEqualsFunction.java index faa77d8..5384af6 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfEqualsFunction.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfEqualsFunction.java @@ -16,7 +16,6 @@ */ package org.apache.marmotta.kiwi.sparql.function.geosparql; - import org.apache.marmotta.kiwi.persistence.KiWiDialect; import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; import org.apache.marmotta.kiwi.sparql.builder.ValueType; @@ -28,24 +27,26 @@ import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; /** - * A SPARQL function for doing a equals between two geometries. Should be implemented directly in - * the database, as the in-memory implementation is non-functional. Only support by postgres - POSTGIS + * A SPARQL function for doing a equals 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:sfEquals(?geometryA, ?geometryB) </li> + * <li>geof:sfEquals(?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. + * 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 Zumba ([email protected])) + * @author Xavier Sumba ([email protected])) */ public class SfEqualsFunction implements NativeFunction { // auto-register for SPARQL environment static { - if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_EQUALS.toString())) { + if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_EQUALS.toString())) { FunctionRegistry.getInstance().add(new SfEqualsFunction()); } } @@ -60,9 +61,9 @@ public class SfEqualsFunction implements NativeFunction { return FN_GEOSPARQL.SF_EQUALS.toString(); } - /** - * Return true if this function has available native support for the given dialect + * Return true if this function has available native support for the given + * dialect * * @param dialect * @return @@ -73,7 +74,8 @@ public class SfEqualsFunction implements NativeFunction { } /** - * Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect + * Return a string representing how this GeoSPARQL function is translated + * into SQL ( Postgis Function ) in the given dialect * * @param dialect * @param args @@ -81,21 +83,21 @@ public class SfEqualsFunction implements NativeFunction { */ @Override public String getNative(KiWiDialect dialect, String... args) { - if(dialect instanceof PostgreSQLDialect) { - if(args.length == 2) { - if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON)|| args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) - { //If users insert Direct the WKT Geometry - return "st_Equals(" + args[0] + " , " + args[1] + " )"; - } - return "st_Equals(" + args[0] + " , " + args[1] + " )"; - } + if (dialect instanceof PostgreSQLDialect) { + if (args.length == 2) { + if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry + return String.format("st_Equals(%s , %s )", args[0], args[1]); + } + return String.format("st_Equals(%s , %s )", args[0], args[1]); + } } - throw new UnsupportedOperationException("sfEquals function not supported by dialect "+dialect); + throw new UnsupportedOperationException("sfEquals function not supported by dialect " + dialect); } /** - * Get the return type of the function. This is needed for SQL type casting inside KiWi. + * Get the return type of the function. This is needed for SQL type casting + * inside KiWi. * * @return */ @@ -105,8 +107,8 @@ public class SfEqualsFunction implements NativeFunction { } /** - * 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. + * 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 http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfIntersectsFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfIntersectsFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfIntersectsFunction.java index 8d34b1f..ab90323 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfIntersectsFunction.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfIntersectsFunction.java @@ -16,37 +16,37 @@ */ package org.apache.marmotta.kiwi.sparql.function.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.apache.marmotta.kiwi.vocabulary.FN_MARMOTTA; 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 intersection between two geometries. Should be implemented directly in - * the database, as the in-memory implementation is non-functional. Only support by postgres - POSTGIS + * A SPARQL function for doing a intersection 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:sfIntersects(?geometryA, ?geometryB) </li> + * <li>geof:sfIntersects(?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. + * 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 Zumba ([email protected])) + * @author Xavier Sumba ([email protected])) */ public class SfIntersectsFunction implements NativeFunction { // auto-register for SPARQL environment static { - if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_INTERSECTS.toString())) { + if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_INTERSECTS.toString())) { FunctionRegistry.getInstance().add(new SfIntersectsFunction()); } } @@ -61,9 +61,9 @@ public class SfIntersectsFunction implements NativeFunction { return FN_GEOSPARQL.SF_INTERSECTS.toString(); } - /** - * Return true if this function has available native support for the given dialect + * Return true if this function has available native support for the given + * dialect * * @param dialect * @return @@ -74,7 +74,8 @@ public class SfIntersectsFunction implements NativeFunction { } /** - * Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect + * Return a string representing how this GeoSPARQL function is translated + * into SQL ( Postgis Function ) in the given dialect * * @param dialect * @param args @@ -82,21 +83,21 @@ public class SfIntersectsFunction implements NativeFunction { */ @Override public String getNative(KiWiDialect dialect, String... args) { - if(dialect instanceof PostgreSQLDialect) { - if(args.length == 2) { - if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON)|| args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) - { //If users insert Direct the WKT Geometry - return "st_Intersects(" + args[0] + " , " + args[1] + " ) "; - } - return "st_Intersects(" + args[0] + " , " + args[1] + " ) "; - } + if (dialect instanceof PostgreSQLDialect) { + if (args.length == 2) { + if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry + return String.format("st_Intersects(%s , %s ) ", args[0], args[1]); + } + return String.format("st_Intersects(%s , %s ) ", args[0], args[1]); + } } - throw new UnsupportedOperationException("Intersects function not supported by dialect "+dialect); + throw new UnsupportedOperationException("Intersects function not supported by dialect " + dialect); } /** - * Get the return type of the function. This is needed for SQL type casting inside KiWi. + * Get the return type of the function. This is needed for SQL type casting + * inside KiWi. * * @return */ @@ -106,8 +107,8 @@ public class SfIntersectsFunction implements NativeFunction { } /** - * 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. + * 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 http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfOverlapsFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfOverlapsFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfOverlapsFunction.java index 9b6a9e8..29e50c6 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfOverlapsFunction.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfOverlapsFunction.java @@ -16,7 +16,6 @@ */ package org.apache.marmotta.kiwi.sparql.function.geosparql; - import org.apache.marmotta.kiwi.persistence.KiWiDialect; import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; import org.apache.marmotta.kiwi.sparql.builder.ValueType; @@ -28,24 +27,26 @@ import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; /** - * A SPARQL function for doing a overlaps between geometries. Should be implemented directly in - * the database, as the in-memory implementation is non-functional. Only support by postgres - POSTGIS + * A SPARQL function for doing a overlaps between 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:sfOverlaps(?geometryA, ?geometryB) </li> + * <li>geof:sfOverlaps(?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. + * 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 Zumba ([email protected])) + * @author Xavier Sumba ([email protected])) */ public class SfOverlapsFunction implements NativeFunction { // auto-register for SPARQL environment static { - if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_OVERLAPS.toString())) { + if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_OVERLAPS.toString())) { FunctionRegistry.getInstance().add(new SfOverlapsFunction()); } } @@ -60,9 +61,9 @@ public class SfOverlapsFunction implements NativeFunction { return FN_GEOSPARQL.SF_OVERLAPS.toString(); } - /** - * Return true if this function has available native support for the given dialect + * Return true if this function has available native support for the given + * dialect * * @param dialect * @return @@ -73,7 +74,8 @@ public class SfOverlapsFunction implements NativeFunction { } /** - * Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect + * Return a string representing how this GeoSPARQL function is translated + * into SQL ( Postgis Function ) in the given dialect * * @param dialect * @param args @@ -81,21 +83,20 @@ public class SfOverlapsFunction implements NativeFunction { */ @Override public String getNative(KiWiDialect dialect, String... args) { - if(dialect instanceof PostgreSQLDialect) { - if(args.length == 2) { - if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON)|| args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) - { //If users insert Direct the WKT Geometry - return "st_Overlaps(" + args[0] + " , " + args[1] + " )"; - } - return "st_Overlaps(" + args[0] + " , " + args[1] + " )"; - } - + if (dialect instanceof PostgreSQLDialect) { + if (args.length == 2) { + if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || args[1].contains(FN_GEOSPARQL.POINT)) { //If users insert Direct the WKT Geometry + return String.format("st_Overlaps(%s , %s )", args[0], args[1]); + } + return String.format("st_Overlaps(%s , %s )", args[0], args[1]); + } } - throw new UnsupportedOperationException("sfOverlaps function not supported by dialect "+dialect); + throw new UnsupportedOperationException("sfOverlaps function not supported by dialect " + dialect); } /** - * Get the return type of the function. This is needed for SQL type casting inside KiWi. + * Get the return type of the function. This is needed for SQL type casting + * inside KiWi. * * @return */ @@ -105,8 +106,8 @@ public class SfOverlapsFunction implements NativeFunction { } /** - * 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. + * 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 http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfTouchesFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfTouchesFunction.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfTouchesFunction.java index 4d5dee3..de46e26 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfTouchesFunction.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfTouchesFunction.java @@ -16,7 +16,6 @@ */ package org.apache.marmotta.kiwi.sparql.function.geosparql; - import org.apache.marmotta.kiwi.persistence.KiWiDialect; import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; import org.apache.marmotta.kiwi.sparql.builder.ValueType; @@ -28,24 +27,26 @@ import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; /** - * A SPARQL function for doing touches analyzer between two geometries. Should be implemented directly in - * the database, as the in-memory implementation is non-functional. Only support by postgres - POSTGIS + * A SPARQL function for doing touches analyzer 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:sfTouches(?geometryA, ?geometryB) </li> + * <li>geof:sfTouches(?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. + * 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 Zumba ([email protected])) + * @author Xavier Sumba ([email protected])) */ public class SfTouchesFunction implements NativeFunction { // auto-register for SPARQL environment static { - if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_TOUCHES.toString())) { + if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_TOUCHES.toString())) { FunctionRegistry.getInstance().add(new SfTouchesFunction()); } } @@ -60,9 +61,9 @@ public class SfTouchesFunction implements NativeFunction { return FN_GEOSPARQL.SF_TOUCHES.toString(); } - /** - * Return true if this function has available native support for the given dialect + * Return true if this function has available native support for the given + * dialect * * @param dialect * @return @@ -73,7 +74,8 @@ public class SfTouchesFunction implements NativeFunction { } /** - * Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect + * Return a string representing how this GeoSPARQL function is translated + * into SQL ( Postgis Function ) in the given dialect * * @param dialect * @param args @@ -81,24 +83,25 @@ public class SfTouchesFunction implements NativeFunction { */ @Override public String getNative(KiWiDialect dialect, String... args) { - if(dialect instanceof PostgreSQLDialect) { - if(args.length == 2) { + if (dialect instanceof PostgreSQLDialect) { + if (args.length == 2) { // if (args[0].contains(FN_GEOSPARQL.POINT.toString()) && args[1].contains(FN_GEOSPARQL.MULTIPOLYGON.toString())) - // { - return "st_Touches(" + args[0] + " , " + args[1] + " )"; + // { + return String.format("st_Touches(%s , %s )", args[0], args[1]); // } - // else - // if (args[0].contains(FN_GEOSPARQL.POINT.toString()) && args[1].contains(FN_GEOSPARQL.MULTILINESTRING.toString())) - // { return "st_Intersects(substring( " + args[0] + " from position('" + FN_GEOSPARQL.POINT.toString() + "' in " + args[0] + " ) for 60 ), substring( " + args[1] + " from position('"+FN_GEOSPARQL.MULTILINESTRING.toString()+"' in " + args[1] + " ) for char_length( " + args[1] + " ) ) ) "; - // } - } + // else + // if (args[0].contains(FN_GEOSPARQL.POINT.toString()) && args[1].contains(FN_GEOSPARQL.MULTILINESTRING.toString())) + // { return "st_Intersects(substring( " + args[0] + " from position('" + FN_GEOSPARQL.POINT.toString() + "' in " + args[0] + " ) for 60 ), substring( " + args[1] + " from position('"+FN_GEOSPARQL.MULTILINESTRING.toString()+"' in " + args[1] + " ) for char_length( " + args[1] + " ) ) ) "; + // } + } } - throw new UnsupportedOperationException("Touches function not supported by dialect "+dialect); + throw new UnsupportedOperationException("Touches function not supported by dialect " + dialect); } /** - * Get the return type of the function. This is needed for SQL type casting inside KiWi. + * Get the return type of the function. This is needed for SQL type casting + * inside KiWi. * * @return */ @@ -108,8 +111,8 @@ public class SfTouchesFunction implements NativeFunction { } /** - * 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. + * 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
