Add GeoSPARQL Functions

Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/d46029a8
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/d46029a8
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/d46029a8

Branch: refs/heads/MARMOTTA-584
Commit: d46029a8663710679d420b4b08c4701a2dfe9d32
Parents: 7faf379
Author: cuent <[email protected]>
Authored: Thu Jul 23 11:03:22 2015 -0500
Committer: cuent <[email protected]>
Committed: Thu Jul 23 11:03:22 2015 -0500

----------------------------------------------------------------------
 .../kiwi/sparql/builder/SQLBuilder.java         |  30 ++--
 .../builder/eval/ValueExpressionEvaluator.java  |   5 +
 .../function/geosparql/BufferFunction.java      | 138 +++++++++++++++++++
 .../function/geosparql/ConvexHullFunction.java  | 138 +++++++++++++++++++
 .../geosparql/IntersectionFunction.java         |  20 ++-
 .../function/geosparql/SfBufferFunction.java    | 137 ------------------
 .../function/geosparql/SfContainsFunction.java  |   9 +-
 .../geosparql/SfConvexHullFunction.java         | 137 ------------------
 .../function/geosparql/SfCrossesFunction.java   |   9 +-
 .../function/geosparql/SfDisjointFunction.java  |   9 +-
 .../function/geosparql/SfEqualsFunction.java    |   9 +-
 .../geosparql/SfIntersectsFunction.java         |  10 +-
 .../function/geosparql/SfOverlapsFunction.java  |   9 +-
 .../function/geosparql/SfTouchesFunction.java   |   7 +-
 .../function/geosparql/SfWithinFunction.java    |   4 +-
 ...marmotta.kiwi.sparql.function.NativeFunction |   4 +-
 ...f.query.algebra.evaluation.function.Function |   6 +-
 17 files changed, 345 insertions(+), 336 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
index c26672d..1c271f9 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
@@ -45,8 +45,7 @@ import java.util.*;
 /**
  * A builder for translating SPARQL queries into SQL.
  *
- * @author Sebastian Schaffert
- * @author Sergio Fernández
+ * @author Sebastian Schaffert ([email protected])
  */
 public class SQLBuilder {
 
@@ -57,6 +56,7 @@ public class SQLBuilder {
      */
     private static final String[] positions = new String[] 
{"subject","predicate","object","context"};
 
+
     /**
      * Reference to the registry of natively supported functions with 
parameter and return types as well as SQL translation
      */
@@ -165,6 +165,7 @@ public class SQLBuilder {
         prepareBuilder();
     }
 
+
     public Map<String, SQLVariable> getVariables() {
         return variables;
     }
@@ -389,7 +390,8 @@ public class SQLBuilder {
                                     
p.getConditions().add(sv.getExpressions().get(0) + " = " + sv.getAlias() + 
".svalue");
                                     break;
                                 case GEOMETRY:
-
+                                    
p.getConditions().add(sv.getExpressions().get(0) + " = " + sv.getAlias() + 
".gvalue");
+                                    break;
                                 default:
                                     
p.getConditions().add(sv.getExpressions().get(0) + " = " + pName + "." + 
positions[i]);
                                     break;
@@ -610,6 +612,7 @@ public class SQLBuilder {
         }
     }
 
+
     private StringBuilder buildSelectClause() {
         List<String> projections = new ArrayList<>();
 
@@ -617,19 +620,17 @@ public class SQLBuilder {
         List<SQLVariable> vars = new ArrayList<>(variables.values());
         Collections.sort(vars, SQLVariable.sparqlNameComparator);
 
+
         for(SQLVariable v : vars) {
             if(v.getProjectionType() != ValueType.NONE && 
(projectedVars.isEmpty() || projectedVars.contains(v.getSparqlName()))) {
                 String projectedName = v.getName();
+                String fromName = v.getExpressions().get(0);
 
-                if (v.getExpressions() != null && v.getExpressions().size() > 
0) {
-                    String fromName = v.getExpressions().get(0);
-                    projections.add(fromName + " AS " + projectedName);
-                }
+                projections.add(fromName + " AS " + projectedName);
 
                 if(v.getLiteralTypeExpression() != null) {
                     projections.add(v.getLiteralTypeExpression() + " AS " + 
projectedName + "_TYPE");
                 }
-                
                 if(v.getLiteralLangExpression() != null) {
                     projections.add(v.getLiteralLangExpression() + " AS " + 
projectedName + "_LANG");
                 }
@@ -792,7 +793,6 @@ public class SQLBuilder {
 
     private StringBuilder buildGroupClause() {
         StringBuilder groupClause = new StringBuilder();
-
         if(groupLabels.size() > 0) {
             for(Iterator<String> it = groupLabels.iterator(); it.hasNext(); ) {
                 SQLVariable sv = variables.get(it.next());
@@ -811,18 +811,6 @@ public class SQLBuilder {
                     groupClause.append(", ");
                 }
             }
-
-            if (orderby.size() > 0) {
-                groupClause.append(", ");
-                for(Iterator<OrderElem> it = orderby.iterator(); it.hasNext(); 
) {
-                    OrderElem elem = it.next();
-                    groupClause.append(evaluateExpression(elem.getExpr(), 
ValueType.STRING));
-                    if (it.hasNext()) {
-                        groupClause.append(", ");
-                    }
-                }
-            }
-
             groupClause.append(" \n");
         }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
index dee6841..df76332 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
@@ -584,6 +584,10 @@ public class ValueExpressionEvaluator extends 
QueryModelVisitorBase<RuntimeExcep
                 // in the database, we take the NODES alias and resolve to the 
correct column according to the
                 // operator type
                 switch (optypes.peek()) {
+                    case GEOMETRY:
+                        Preconditions.checkState(var != null, "no alias 
available for variable");
+                        builder.append(var).append(".gvalue");
+                        break;
                     case STRING:
                         Preconditions.checkState(var != null, "no alias 
available for variable");
                         builder.append(var).append(".svalue");
@@ -633,6 +637,7 @@ public class ValueExpressionEvaluator extends 
QueryModelVisitorBase<RuntimeExcep
         String val = node.getValue().stringValue();
 
             switch (optypes.peek()) {
+                case GEOMETRY:
                 case STRING:
                 case URI:
                     builder.append("'").append(val).append("'");

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/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
new file mode 100644
index 0000000..fa3901a
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/BufferFunction.java
@@ -0,0 +1,138 @@
+/*
+ * 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 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>
+ * </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 Zumba ([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 == 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] + " )) 
";
+            } 
+
+        }
+        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 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/d46029a8/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
new file mode 100644
index 0000000..89973d5
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/ConvexHullFunction.java
@@ -0,0 +1,138 @@
+/*
+ * 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 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) {
+                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] +"))";
+            } 
+
+        }
+        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/d46029a8/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 1f523c2..790d1da 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,6 +16,7 @@
  */
 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;
@@ -38,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 Sumba ([email protected])
+ * @author Xavier Sumba ([email protected]))
  */
 public class IntersectionFunction implements NativeFunction {
 
@@ -81,13 +82,18 @@ public class IntersectionFunction 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 String.format("ST_AsText(st_Intersection(substring( 
%s from position(' ' in %s) + 1 for char_length( %s ) ), %s ) )", args[0], 
args[0], 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 "ST_AsText(st_Intersection(" + args[0] + " , " + 
args[1] + " ) )";    
                 }        
-                return String.format("ST_AsText(st_Intersection(substring( %s 
from position(' ' in %s) + 1 for char_length( %s ) ), substring( %s from 
position(' ' in %s) + 1 for char_length( %s ) ) ) )", args[0], args[0], 
args[0], args[1], args[1], args[1]);
+                return "ST_AsText(st_Intersection(" + args[0] + " , " + 
args[1] + " ) )";
             } 
+
+            
+            
+            
         }
         throw new UnsupportedOperationException("intersection function not 
supported by dialect "+dialect);
     }
@@ -111,7 +117,7 @@ public class IntersectionFunction implements NativeFunction 
{
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.STRING;
+        return ValueType.GEOMETRY;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfBufferFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfBufferFunction.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfBufferFunction.java
deleted file mode 100644
index fcc8810..0000000
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfBufferFunction.java
+++ /dev/null
@@ -1,137 +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.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 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>
- * </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 SfBufferFunction implements NativeFunction {
-
-    // auto-register for SPARQL environment
-    static {
-        
if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.BUFFER.toString())) {
-            FunctionRegistry.getInstance().add(new SfBufferFunction());
-        }
-    }
-
-    @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 == 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(substring( %s 
from position(' ' in %s) + 1 for char_length( %s ) ), %s )) ", args[0], 
args[0], args[0], args[1]);     
-                }        
-            return String.format("ST_AsText(st_Buffer(substring( %s from 
position(' ' in %s) + 1 for char_length( %s ) ), %s )) ", args[0], args[0], 
args[0], 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.STRING;
-    }
-
-    /**
-     * 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/d46029a8/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 2c0c354..a7df54f 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
@@ -16,6 +16,7 @@
  */
 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;
@@ -38,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 Sumba ([email protected])
+ * @author Xavier Zumba ([email protected]))
  */
 public class SfContainsFunction implements NativeFunction {
 
@@ -84,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 String.format("st_Contains(substring( %s from 
position(' ' in %s) + 1 for char_length( %s ) ), %s )", args[0], args[0], 
args[0], args[1]);  
+                    return "st_Contains(" + args[0] + " , " + args[1] + " )";  
  
                 }        
-                return String.format("st_Contains(substring( %s from 
position(' ' in %s) + 1 for char_length( %s ) ), substring( %s from position(' 
' in %s) + 1 for char_length( %s ) ) ) ", args[0], args[0], args[0], args[1], 
args[1], args[1]);
+                return "st_Contains(" + args[0] + " , " +  args[1] + " )";
             } 
 
         }
@@ -112,7 +113,7 @@ public class SfContainsFunction implements NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.STRING;
+        return ValueType.GEOMETRY;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfConvexHullFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfConvexHullFunction.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfConvexHullFunction.java
deleted file mode 100644
index cdc0bf6..0000000
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfConvexHullFunction.java
+++ /dev/null
@@ -1,137 +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.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 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 SfConvexHullFunction implements NativeFunction {
-
-    // auto-register for SPARQL environment
-    static {
-        
if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.CONVEX_HULL.toString())) {
-            FunctionRegistry.getInstance().add(new SfConvexHullFunction());
-        }
-    }
-
-    @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) {
-                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(substring( %s 
from position(' ' in %s) + 1 for char_length( %s )))) ", args[0], args[0], 
args[0]);
-            } 
-
-        }
-        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.STRING;
-    }
-
-    /**
-     * 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;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/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 ff28d17..2dbe7f3 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,6 +16,7 @@
  */
 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;
@@ -38,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 Sumba ([email protected])
+ * @author Xavier Zumba ([email protected]))
  */
 public class SfCrossesFunction implements NativeFunction {
 
@@ -84,9 +85,9 @@ public class SfCrossesFunction 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 String.format("st_Crosses(substring( %s from 
position(' ' in %s) + 1 for char_length( %s ) ), %s )", args[0], args[0], 
args[0], args[1]);
+                    return "st_Crosses(" + args[0] + " , " + args[1] + " )";   
 
                 }        
-                return String.format("st_Crosses(substring( %s from position(' 
' in %s) + 1 for char_length( %s ) ), substring( %s from position(' ' in %s) + 
1 for char_length( %s ) ) ) ", args[0], args[0], args[0], args[1], args[1], 
args[1]);
+                return "st_Crosses(" + args[0] + " , " + args[1] + " )";
             } 
 
         }
@@ -112,7 +113,7 @@ public class SfCrossesFunction implements NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.STRING;
+        return ValueType.GEOMETRY;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/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 f6f55ea..9651ee1 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,6 +16,7 @@
  */
 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;
@@ -38,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 Sumba ([email protected])
+ * @author Xavier Zumba ([email protected]))
  */
 public class SfDisjointFunction implements NativeFunction {
 
@@ -84,9 +85,9 @@ public class SfDisjointFunction 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 String.format("st_Disjoint(substring( %s from 
position(' ' in %s) + 1 for char_length( %s ) ), %s )", args[0], args[0], 
args[0], args[1]);
+                    return "st_Disjoint(" + args[0] + " , " + args[1] + " )";  
  
                 }        
-                return String.format("st_Disjoint(substring( %s from 
position(' ' in %s) + 1 for char_length( %s ) ), substring( %s from position(' 
' in %s) + 1 for char_length( %s ) ) ) ", args[0], args[0], args[0], args[1], 
args[1], args[1]);
+                return "st_Disjoint(" + args[0] + " , " + args[1] + " )";
             } 
 
         }
@@ -112,7 +113,7 @@ public class SfDisjointFunction implements NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.STRING;
+        return ValueType.GEOMETRY;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/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 3204dd1..faa77d8 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,6 +16,7 @@
  */
 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;
@@ -38,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 Sumba ([email protected])
+ * @author Xavier Zumba ([email protected]))
  */
 public class SfEqualsFunction implements NativeFunction {
 
@@ -84,9 +85,9 @@ public class SfEqualsFunction 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 String.format("st_Equals(substring( %s from 
position(' ' in %s) + 1 for char_length( %s ) ), %s )", args[0], args[0], 
args[0], args[1]);
+                    return "st_Equals(" + args[0] + " , " + args[1] + " )";    
                 }        
-                return String.format("st_Equals(substring( %s from position(' 
' in %s) + 1 for char_length( %s ) ), substring( %s from position(' ' in %s) + 
1 for char_length( %s ) ) ) ", args[0], args[0], args[0], args[1], args[1], 
args[1]);
+                return "st_Equals(" + args[0] + " , " + args[1] + " )";    
             } 
 
         }
@@ -112,7 +113,7 @@ public class SfEqualsFunction implements NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.STRING;
+        return ValueType.GEOMETRY;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/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 3aaefd7..8d34b1f 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,11 +16,13 @@
  */
 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;
@@ -38,7 +40,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 Sumba ([email protected])
+ * @author Xavier Zumba ([email protected]))
  */
 public class SfIntersectsFunction implements NativeFunction {
 
@@ -84,9 +86,9 @@ public class SfIntersectsFunction 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 String.format("st_Intersects(substring( %s from 
position(' ' in %s) + 1 for char_length( %s ) ), %s )", args[0], args[0], 
args[0], args[1]);
+                    return "st_Intersects(" + args[0] + " , " + args[1] + " ) 
";    
                 }        
-                return String.format("st_Intersects(substring( %s from 
position(' ' in %s) + 1 for char_length( %s ) ), substring( %s from position(' 
' in %s) + 1 for char_length( %s ) ) ) ", args[0], args[0], args[0], args[1], 
args[1], args[1]);
+                return "st_Intersects(" + args[0] + " , " + args[1] + " ) ";
             } 
 
         }
@@ -112,7 +114,7 @@ public class SfIntersectsFunction implements NativeFunction 
{
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.STRING;
+        return ValueType.GEOMETRY;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/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 3b3cb07..9b6a9e8 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,6 +16,7 @@
  */
 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;
@@ -38,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 Sumba ([email protected])
+ * @author Xavier Zumba ([email protected]))
  */
 public class SfOverlapsFunction implements NativeFunction {
 
@@ -84,9 +85,9 @@ public class SfOverlapsFunction 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 String.format("st_Overlaps(substring( %s from 
position(' ' in %s) + 1 for char_length( %s ) ), %s )", args[0], args[0], 
args[0], args[1]);
+                    return "st_Overlaps(" + args[0] + " , " + args[1] + " )";  
  
                 }        
-                return String.format("st_Overlaps(substring( %s from 
position(' ' in %s) + 1 for char_length( %s ) ), substring( %s from position(' 
' in %s) + 1 for char_length( %s ) ) ) ", args[0], args[0], args[0], args[1], 
args[1], args[1]);
+                return "st_Overlaps(" + args[0] + " , " + args[1] + " )";
             } 
 
         }
@@ -112,7 +113,7 @@ public class SfOverlapsFunction implements NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.STRING;
+        return ValueType.GEOMETRY;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/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 8cd4d07..4d5dee3 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,6 +16,7 @@
  */
 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;
@@ -38,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 Sumba ([email protected])
+ * @author Xavier Zumba ([email protected]))
  */
 public class SfTouchesFunction implements NativeFunction {
 
@@ -84,7 +85,7 @@ public class SfTouchesFunction implements NativeFunction {
             if(args.length == 2) {
          //       if (args[0].contains(FN_GEOSPARQL.POINT.toString()) && 
args[1].contains(FN_GEOSPARQL.MULTIPOLYGON.toString()))
          //       { 
-                return String.format("st_Touches(substring( %s from position(' 
' in %s) + 1 for char_length( %s ) ), substring( %s from position(' ' in %s) + 
1 for char_length( %s ) ) ) ", args[0], args[0], args[0], args[1], args[1], 
args[1]);
+                return "st_Touches(" + args[0] + " , " + args[1] + " )";
               //  }
             //    else
            //     if (args[0].contains(FN_GEOSPARQL.POINT.toString()) && 
args[1].contains(FN_GEOSPARQL.MULTILINESTRING.toString()))
@@ -115,7 +116,7 @@ public class SfTouchesFunction implements NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.STRING;
+        return ValueType.GEOMETRY;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfWithinFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfWithinFunction.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfWithinFunction.java
index 90fb5c8..69f57b5 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfWithinFunction.java
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfWithinFunction.java
@@ -85,7 +85,7 @@ public class SfWithinFunction implements NativeFunction {
             if(args.length == 2) {
          //       if (args[0].contains(FN_GEOSPARQL.POINT.toString()) && 
args[1].contains(FN_GEOSPARQL.MULTIPOLYGON.toString()))
          //       { 
-                return String.format("st_Within(substring( %s from position(' 
' in %s) + 1 for char_length( %s ) ), substring( %s from position(' ' in %s) + 
1 for char_length( %s ) ) ) ", args[0], args[0], args[0], args[1], args[1], 
args[1]);
+                return "st_Within("+args[0]+","+args[1]+")";
               //  }
             //    else
            //     if (args[0].contains(FN_GEOSPARQL.POINT.toString()) && 
args[1].contains(FN_GEOSPARQL.MULTILINESTRING.toString()))
@@ -116,7 +116,7 @@ public class SfWithinFunction implements NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.STRING;
+        return ValueType.GEOMETRY;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/libraries/kiwi/kiwi-sparql/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.sparql.function.NativeFunction
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.sparql.function.NativeFunction
 
b/libraries/kiwi/kiwi-sparql/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.sparql.function.NativeFunction
index 0234578..42d4694 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.sparql.function.NativeFunction
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.sparql.function.NativeFunction
@@ -24,8 +24,8 @@ 
org.apache.marmotta.kiwi.sparql.function.geosparql.SfDisjointFunction
 org.apache.marmotta.kiwi.sparql.function.geosparql.SfEqualsFunction
 org.apache.marmotta.kiwi.sparql.function.geosparql.SfOverlapsFunction
 
-org.apache.marmotta.kiwi.sparql.function.geosparql.SfBufferFunction
-org.apache.marmotta.kiwi.sparql.function.geosparql.SfConvexHullFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.BufferFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.ConvexHullFunction
 org.apache.marmotta.kiwi.sparql.function.geosparql.IntersectionFunction
 
 org.apache.marmotta.kiwi.sparql.function.cast.NBooleanCast

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46029a8/libraries/kiwi/kiwi-sparql/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function
 
b/libraries/kiwi/kiwi-sparql/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function
index f445a12..2d7dac3 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function
@@ -12,6 +12,6 @@ 
org.apache.marmotta.kiwi.sparql.function.geosparql.SfDisjointFunction
 org.apache.marmotta.kiwi.sparql.function.geosparql.SfEqualsFunction
 org.apache.marmotta.kiwi.sparql.function.geosparql.SfOverlapsFunction
 
-org.apache.marmotta.kiwi.sparql.function.geosparql.SfBufferFunction
-org.apache.marmotta.kiwi.sparql.function.geosparql.SfConvexHullFunction
-org.apache.marmotta.kiwi.sparql.function.geosparql.IntersectionFunction
\ No newline at end of file
+org.apache.marmotta.kiwi.sparql.function.geosparql.BufferFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.ConvexHullFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.IntersectionFunction

Reply via email to