marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wik...@apache.org
Subject [02/40] marmotta git commit: Functions geosparql, added 10 functions.
Date Mon, 24 Aug 2015 08:13:57 GMT
Functions geosparql, added 10 functions.

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

Branch: refs/heads/MARMOTTA-584
Commit: 480e7243f95584719dd63ea861c35525c9eb5247
Parents: e074cb1
Author: cuent <cuent@172.28.247.158>
Authored: Thu Jun 18 16:46:59 2015 -0500
Committer: cuent <cuent@172.28.247.158>
Committed: Thu Jun 18 16:46:59 2015 -0500

----------------------------------------------------------------------
 .../kiwi/sparql/builder/SQLBuilder.java         |   1 +
 .../marmotta/kiwi/sparql/builder/ValueType.java |   3 +-
 .../function/geosparql/SfBufferFunction.java    | 138 ++++++++++++++++++
 .../function/geosparql/SfContainsFunction.java  | 138 ++++++++++++++++++
 .../geosparql/SfConvexHullFunction.java         | 138 ++++++++++++++++++
 .../function/geosparql/SfCrossesFunction.java   | 138 ++++++++++++++++++
 .../function/geosparql/SfDisjointFunction.java  | 138 ++++++++++++++++++
 .../function/geosparql/SfEqualsFunction.java    | 138 ++++++++++++++++++
 .../geosparql/SfIntersectsFunction.java         | 139 ++++++++++++++++++
 .../function/geosparql/SfOverlapsFunction.java  | 138 ++++++++++++++++++
 .../function/geosparql/SfTouchesFunction.java   | 141 +++++++++++++++++++
 .../function/geosparql/SfWithinFunction.java    | 141 +++++++++++++++++++
 ...marmotta.kiwi.sparql.function.NativeFunction |  12 ++
 ...f.query.algebra.evaluation.function.Function |  14 +-
 14 files changed, 1415 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/480e7243/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 933fdda..c26672d 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
@@ -388,6 +388,7 @@ public class SQLBuilder {
                                 case STRING:
                                     p.getConditions().add(sv.getExpressions().get(0) + " = " + sv.getAlias() + ".svalue");
                                     break;
+                                case GEOMETRY:
 
                                 default:
                                     p.getConditions().add(sv.getExpressions().get(0) + " = " + pName + "." + positions[i]);

http://git-wip-us.apache.org/repos/asf/marmotta/blob/480e7243/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
index f33200c..34576ca 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
@@ -34,7 +34,8 @@ public enum ValueType {
     TERM,   // value of constructed term
     URI,    // constructed URI
     BNODE,  // constructed BNODE
-    NONE;    // not projected
+    NONE,    // not projected
+    GEOMETRY; //geometry value
 
 
     public final boolean isNumeric() {

http://git-wip-us.apache.org/repos/asf/marmotta/blob/480e7243/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
new file mode 100644
index 0000000..ccddd0e
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfBufferFunction.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 Sumba (xavier.sumba93@ucuenca.ec))
+ */
+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 "ST_AsText(st_Buffer(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), " + args[1] + " ))";    
+                }        
+                return "ST_AsText(st_Buffer(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + 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/480e7243/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
new file mode 100644
index 0000000..0fae34e
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfContainsFunction.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 geometry that contains another 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:sfContains(?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 (xavier.sumba93@ucuenca.ec))
+ */
+public class SfContainsFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_CONTAINS.toString())) {
+            FunctionRegistry.getInstance().add(new SfContainsFunction());
+        }
+    }
+
+    @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.SF_CONTAINS.toString();
+    }
+
+
+    /**
+     * Return true if this function has available native support for the given dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if(dialect instanceof PostgreSQLDialect) {
+            if(args.length == 2) {
+                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(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), " + args[1] + " )";    
+                }        
+                return "st_Contains(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), substring( " + args[1] + " from position(' ' in " +  args[1] + ") + 1 for char_length( " + args[1] + " ) ) ) ";
+            } 
+
+        }
+        throw new UnsupportedOperationException("sfContains 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.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/480e7243/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
new file mode 100644
index 0000000..747bced
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfConvexHullFunction.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 (xavier.sumba93@ucuenca.ec))
+ */
+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 "ST_AsText(st_convexHull( " + args[0] + " ))";    
+                }        
+                return "ST_AsText(st_convexHull(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + 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/480e7243/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
new file mode 100644
index 0000000..b73790c
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfCrossesFunction.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 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>
+ * </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 (xavier.sumba93@ucuenca.ec))
+ */
+public class SfCrossesFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_CROSSES.toString())) {
+            FunctionRegistry.getInstance().add(new SfCrossesFunction());
+        }
+    }
+
+    @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.SF_CROSSES.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_Crosses(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), " + args[1] + " )";    
+                }        
+                return "st_Crosses(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), substring( " + args[1] + " from position(' ' in " +  args[1] + ") + 1 for char_length( " + args[1] + " ) ) ) ";
+            } 
+
+        }
+        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.
+     *
+     * @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.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/480e7243/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
new file mode 100644
index 0000000..22d01a3
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfDisjointFunction.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 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>
+ * </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 (xavier.sumba93@ucuenca.ec))
+ */
+public class SfDisjointFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_DISJOINT.toString())) {
+            FunctionRegistry.getInstance().add(new SfDisjointFunction());
+        }
+    }
+
+    @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.SF_DISJOINT.toString();
+    }
+
+
+    /**
+     * Return true if this function has available native support for the given dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if(dialect instanceof PostgreSQLDialect) {
+            if(args.length == 2) {
+                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(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), " + args[1] + " )";    
+                }        
+                return "st_Disjoint(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), substring( " + args[1] + " from position(' ' in " +  args[1] + ") + 1 for char_length( " + args[1] + " ) ) ) ";
+            } 
+
+        }
+        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.
+     *
+     * @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.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/480e7243/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
new file mode 100644
index 0000000..5e869f2
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfEqualsFunction.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 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>
+ * </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 (xavier.sumba93@ucuenca.ec))
+ */
+public class SfEqualsFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_EQUALS.toString())) {
+            FunctionRegistry.getInstance().add(new SfEqualsFunction());
+        }
+    }
+
+    @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.SF_EQUALS.toString();
+    }
+
+
+    /**
+     * Return true if this function has available native support for the given dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if(dialect instanceof PostgreSQLDialect) {
+            if(args.length == 2) {
+                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(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), " + args[1] + " )";    
+                }        
+                return "st_Equals(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), substring( " + args[1] + " from position(' ' in " +  args[1] + ") + 1 for char_length( " + args[1] + " ) ) ) ";
+            } 
+
+        }
+        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.
+     *
+     * @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.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/480e7243/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
new file mode 100644
index 0000000..b6aaf59
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfIntersectsFunction.java
@@ -0,0 +1,139 @@
+/*
+ * 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.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
+ * <p/>
+ * The function can be called either as:
+ * <ul>
+ *     <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.
+ *
+ * @author Xavier Sumba (xavier.sumba93@ucuenca.ec))
+ */
+public class SfIntersectsFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_INTERSECTS.toString())) {
+            FunctionRegistry.getInstance().add(new SfIntersectsFunction());
+        }
+    }
+
+    @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.SF_INTERSECTS.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_Intersects(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), " + args[1] + " )";    
+                }        
+                return "st_Intersects(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), substring( " + args[1] + " from position(' ' in " +  args[1] + ") + 1 for char_length( " + args[1] + " ) ) ) ";
+            } 
+
+        }
+        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.
+     *
+     * @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.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/480e7243/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
new file mode 100644
index 0000000..3a42afd
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfOverlapsFunction.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 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>
+ * </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 (xavier.sumba93@ucuenca.ec))
+ */
+public class SfOverlapsFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_OVERLAPS.toString())) {
+            FunctionRegistry.getInstance().add(new SfOverlapsFunction());
+        }
+    }
+
+    @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.SF_OVERLAPS.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_Overlaps(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), " + args[1] + " )";    
+                }        
+                return "st_Overlaps(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), substring( " + args[1] + " from position(' ' in " +  args[1] + ") + 1 for char_length( " + args[1] + " ) ) ) ";
+            } 
+
+        }
+        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.
+     *
+     * @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.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/480e7243/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
new file mode 100644
index 0000000..0d37973
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfTouchesFunction.java
@@ -0,0 +1,141 @@
+/*
+ * 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  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>
+ * </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 (xavier.sumba93@ucuenca.ec))
+ */
+public class SfTouchesFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_TOUCHES.toString())) {
+            FunctionRegistry.getInstance().add(new SfTouchesFunction());
+        }
+    }
+
+    @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.SF_TOUCHES.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[0].contains(FN_GEOSPARQL.POINT.toString()) && args[1].contains(FN_GEOSPARQL.MULTIPOLYGON.toString()))
+         //       { 
+                return "st_Touches(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), substring( " + args[1] + " from position(' ' in " +  args[1] + ") + 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);
+    }
+
+    /**
+     * 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.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/480e7243/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
new file mode 100644
index 0000000..ea0286e
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SfWithinFunction.java
@@ -0,0 +1,141 @@
+/*
+ * 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 within 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:sfWithin(?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 (xavier.sumba93@ucuenca.ec))
+ */
+public class SfWithinFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_WITHIN.toString())) {
+            FunctionRegistry.getInstance().add(new SfWithinFunction());
+        }
+    }
+
+    @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.SF_WITHIN.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[0].contains(FN_GEOSPARQL.POINT.toString()) && args[1].contains(FN_GEOSPARQL.MULTIPOLYGON.toString()))
+         //       { 
+                return "st_Within(substring( " + args[0] + " from position(' ' in " +  args[0] + ") + 1 for char_length( " + args[0] + " ) ), substring( " + args[1] + " from position(' ' in " +  args[1] + ") + 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("Within 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.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/480e7243/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 7fd19fb..2bb353b 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
@@ -15,6 +15,18 @@
 # limitations under the License.
 #
 
+org.apache.marmotta.kiwi.sparql.function.geosparql.SfIntersectsFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.SfWithinFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.SfTouchesFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.SfContainsFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.SfCrossesFunction
+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.cast.NBooleanCast
 org.apache.marmotta.kiwi.sparql.function.cast.NDateTimeCast
 org.apache.marmotta.kiwi.sparql.function.cast.NDecimalCast

http://git-wip-us.apache.org/repos/asf/marmotta/blob/480e7243/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 4219040..cc8bcb7 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
@@ -1,4 +1,16 @@
 org.apache.marmotta.kiwi.sparql.function.custom.FulltextSearchFunction
 org.apache.marmotta.kiwi.sparql.function.custom.FulltextQueryFunction
 org.apache.marmotta.kiwi.sparql.function.custom.Stddev
-org.apache.marmotta.kiwi.sparql.function.custom.Variance
\ No newline at end of file
+org.apache.marmotta.kiwi.sparql.function.custom.Variance
+
+org.apache.marmotta.kiwi.sparql.function.geosparql.SfIntersectsFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.SfWithinFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.SfTouchesFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.SfContainsFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.SfCrossesFunction
+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
\ No newline at end of file


Mime
View raw message