MARMOTTA-584: extracted geosparql support to a separated module

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

Branch: refs/heads/MARMOTTA-584
Commit: b93cdc78b32387fa21f6ec6d5d1a41ff877e3ca1
Parents: 47702ed
Author: Sergio Fernández <[email protected]>
Authored: Fri Sep 11 09:14:23 2015 +0200
Committer: Sergio Fernández <[email protected]>
Committed: Fri Sep 11 09:14:23 2015 +0200

----------------------------------------------------------------------
 libraries/kiwi/kiwi-geosparql/pom.xml           | 134 ++++++++
 .../kiwi/sparql/geosparql/BoundaryFunction.java | 148 ++++++++
 .../kiwi/sparql/geosparql/BufferFunction.java   | 156 +++++++++
 .../sparql/geosparql/ConvexHullFunction.java    | 149 ++++++++
 .../sparql/geosparql/DifferenceFunction.java    | 153 +++++++++
 .../kiwi/sparql/geosparql/DistanceFunction.java | 160 +++++++++
 .../sparql/geosparql/EhContainsFunction.java    | 152 +++++++++
 .../sparql/geosparql/EhCoveredByFunction.java   | 152 +++++++++
 .../kiwi/sparql/geosparql/EhCoversFunction.java | 152 +++++++++
 .../sparql/geosparql/EhDisjointFunction.java    | 152 +++++++++
 .../kiwi/sparql/geosparql/EhEqualsFunction.java | 152 +++++++++
 .../kiwi/sparql/geosparql/EhInsideFunction.java | 152 +++++++++
 .../kiwi/sparql/geosparql/EhMeetFunction.java   | 152 +++++++++
 .../sparql/geosparql/EhOverlapFunction.java     | 153 +++++++++
 .../kiwi/sparql/geosparql/EnvelopeFunction.java | 148 ++++++++
 .../kiwi/sparql/geosparql/GetSRIDFunction.java  | 136 ++++++++
 .../sparql/geosparql/IntersectionFunction.java  | 152 +++++++++
 .../kiwi/sparql/geosparql/Rcc8DCFunction.java   | 152 +++++++++
 .../kiwi/sparql/geosparql/Rcc8ECFunction.java   | 152 +++++++++
 .../kiwi/sparql/geosparql/Rcc8EQFunction.java   | 152 +++++++++
 .../kiwi/sparql/geosparql/Rcc8NTPPFunction.java | 152 +++++++++
 .../sparql/geosparql/Rcc8NTPPiFunction.java     | 152 +++++++++
 .../kiwi/sparql/geosparql/Rcc8POFunction.java   | 152 +++++++++
 .../kiwi/sparql/geosparql/Rcc8TPPFunction.java  | 152 +++++++++
 .../kiwi/sparql/geosparql/Rcc8TPPiFunction.java | 152 +++++++++
 .../kiwi/sparql/geosparql/RelateFunction.java   | 152 +++++++++
 .../sparql/geosparql/SfContainsFunction.java    | 152 +++++++++
 .../sparql/geosparql/SfCrossesFunction.java     | 152 +++++++++
 .../sparql/geosparql/SfDisjointFunction.java    | 152 +++++++++
 .../kiwi/sparql/geosparql/SfEqualsFunction.java | 152 +++++++++
 .../sparql/geosparql/SfIntersectsFunction.java  | 152 +++++++++
 .../sparql/geosparql/SfOverlapsFunction.java    | 152 +++++++++
 .../sparql/geosparql/SfTouchesFunction.java     | 152 +++++++++
 .../kiwi/sparql/geosparql/SfWithinFunction.java | 152 +++++++++
 .../sparql/geosparql/SymDifferenceFunction.java | 152 +++++++++
 .../kiwi/sparql/geosparql/UnionFunction.java    | 152 +++++++++
 ...marmotta.kiwi.sparql.function.NativeFunction |  55 +++
 ...f.query.algebra.evaluation.function.Function |  55 +++
 .../geosparql/GeoSPARQLFunctionsTest.java       | 342 +++++++++++++++++++
 .../src/test/resources/boundary.sparql          |  28 ++
 .../src/test/resources/buffer.sparql            |  30 ++
 .../src/test/resources/convexHull.sparql        |  28 ++
 .../resources/demo_data_spain_provinces.rdf     |  66 ++++
 .../test/resources/demo_data_spain_rivers.rdf   |  95 ++++++
 .../test/resources/demo_data_spain_towns.rdf    |  95 ++++++
 .../src/test/resources/difference.sparql        |  33 ++
 .../src/test/resources/distance.sparql          |  36 ++
 .../src/test/resources/ehContains.sparql        |  35 ++
 .../src/test/resources/ehCoveredBy.sparql       |  35 ++
 .../src/test/resources/ehCovers.sparql          |  35 ++
 .../src/test/resources/ehDisjoint.sparql        |  35 ++
 .../src/test/resources/ehEquals.sparql          |  34 ++
 .../src/test/resources/ehInside.sparql          |  35 ++
 .../src/test/resources/ehMeet.sparql            |  37 ++
 .../src/test/resources/ehOverlap.sparql         |  35 ++
 .../src/test/resources/envelope.sparql          |  28 ++
 .../src/test/resources/getSRID.sparql           |  30 ++
 .../src/test/resources/intersection.sparql      |  33 ++
 .../src/test/resources/rcc8dc.sparql            |  35 ++
 .../src/test/resources/rcc8ec.sparql            |  37 ++
 .../src/test/resources/rcc8eq.sparql            |  35 ++
 .../src/test/resources/rcc8ntpp.sparql          |  35 ++
 .../src/test/resources/rcc8ntppi.sparql         |  35 ++
 .../src/test/resources/rcc8po.sparql            |  37 ++
 .../src/test/resources/rcc8tpp.sparql           |  35 ++
 .../src/test/resources/rcc8tppi.sparql          |  35 ++
 .../src/test/resources/relate.sparql            |  35 ++
 .../src/test/resources/sfContains.sparql        |  35 ++
 .../src/test/resources/sfCrosses.sparql         |  35 ++
 .../src/test/resources/sfDisjoint.sparql        |  35 ++
 .../src/test/resources/sfEquals.sparql          |  34 ++
 .../src/test/resources/sfIntersects.sparql      |  35 ++
 .../src/test/resources/sfOverlaps.sparql        |  35 ++
 .../src/test/resources/sfTouches.sparql         |  35 ++
 .../src/test/resources/sfWithin.sparql          |  35 ++
 .../src/test/resources/symDifference.sparql     |  33 ++
 .../src/test/resources/union.sparql             |  33 ++
 .../sparql/function/NativeFunctionRegistry.java |   1 +
 .../function/geosparql/BoundaryFunction.java    | 148 --------
 .../function/geosparql/BufferFunction.java      | 156 ---------
 .../function/geosparql/ConvexHullFunction.java  | 149 --------
 .../function/geosparql/DifferenceFunction.java  | 153 ---------
 .../function/geosparql/DistanceFunction.java    | 160 ---------
 .../function/geosparql/EhContainsFunction.java  | 152 ---------
 .../function/geosparql/EhCoveredByFunction.java | 152 ---------
 .../function/geosparql/EhCoversFunction.java    | 152 ---------
 .../function/geosparql/EhDisjointFunction.java  | 152 ---------
 .../function/geosparql/EhEqualsFunction.java    | 152 ---------
 .../function/geosparql/EhInsideFunction.java    | 152 ---------
 .../function/geosparql/EhMeetFunction.java      | 152 ---------
 .../function/geosparql/EhOverlapFunction.java   | 153 ---------
 .../function/geosparql/EnvelopeFunction.java    | 148 --------
 .../function/geosparql/GetSRIDFunction.java     | 136 --------
 .../geosparql/IntersectionFunction.java         | 152 ---------
 .../function/geosparql/Rcc8DCFunction.java      | 152 ---------
 .../function/geosparql/Rcc8ECFunction.java      | 152 ---------
 .../function/geosparql/Rcc8EQFunction.java      | 152 ---------
 .../function/geosparql/Rcc8NTPPFunction.java    | 152 ---------
 .../function/geosparql/Rcc8NTPPiFunction.java   | 152 ---------
 .../function/geosparql/Rcc8POFunction.java      | 152 ---------
 .../function/geosparql/Rcc8TPPFunction.java     | 152 ---------
 .../function/geosparql/Rcc8TPPiFunction.java    | 152 ---------
 .../function/geosparql/RelateFunction.java      | 152 ---------
 .../function/geosparql/SfContainsFunction.java  | 152 ---------
 .../function/geosparql/SfCrossesFunction.java   | 152 ---------
 .../function/geosparql/SfDisjointFunction.java  | 152 ---------
 .../function/geosparql/SfEqualsFunction.java    | 152 ---------
 .../geosparql/SfIntersectsFunction.java         | 152 ---------
 .../function/geosparql/SfOverlapsFunction.java  | 152 ---------
 .../function/geosparql/SfTouchesFunction.java   | 152 ---------
 .../function/geosparql/SfWithinFunction.java    | 152 ---------
 .../geosparql/SymDifferenceFunction.java        | 152 ---------
 .../function/geosparql/UnionFunction.java       | 152 ---------
 ...marmotta.kiwi.sparql.function.NativeFunction |  41 +--
 ...f.query.algebra.evaluation.function.Function |  56 +--
 .../testgeosparql/GeoSPARQLFunctionsTest.java   | 340 ------------------
 .../kiwi/sparql/testgeosparql/boundary.sparql   |  28 --
 .../kiwi/sparql/testgeosparql/buffer.sparql     |  30 --
 .../kiwi/sparql/testgeosparql/convexHull.sparql |  28 --
 .../testgeosparql/demo_data_spain_provinces.rdf |  66 ----
 .../testgeosparql/demo_data_spain_rivers.rdf    |  95 ------
 .../testgeosparql/demo_data_spain_towns.rdf     |  95 ------
 .../kiwi/sparql/testgeosparql/difference.sparql |  33 --
 .../kiwi/sparql/testgeosparql/distance.sparql   |  36 --
 .../kiwi/sparql/testgeosparql/ehContains.sparql |  35 --
 .../sparql/testgeosparql/ehCoveredBy.sparql     |  35 --
 .../kiwi/sparql/testgeosparql/ehCovers.sparql   |  35 --
 .../kiwi/sparql/testgeosparql/ehDisjoint.sparql |  35 --
 .../kiwi/sparql/testgeosparql/ehEquals.sparql   |  34 --
 .../kiwi/sparql/testgeosparql/ehInside.sparql   |  35 --
 .../kiwi/sparql/testgeosparql/ehMeet.sparql     |  37 --
 .../kiwi/sparql/testgeosparql/ehOverlap.sparql  |  35 --
 .../kiwi/sparql/testgeosparql/envelope.sparql   |  28 --
 .../kiwi/sparql/testgeosparql/getSRID.sparql    |  30 --
 .../sparql/testgeosparql/intersection.sparql    |  33 --
 .../kiwi/sparql/testgeosparql/rcc8dc.sparql     |  35 --
 .../kiwi/sparql/testgeosparql/rcc8ec.sparql     |  37 --
 .../kiwi/sparql/testgeosparql/rcc8eq.sparql     |  35 --
 .../kiwi/sparql/testgeosparql/rcc8ntpp.sparql   |  35 --
 .../kiwi/sparql/testgeosparql/rcc8ntppi.sparql  |  35 --
 .../kiwi/sparql/testgeosparql/rcc8po.sparql     |  37 --
 .../kiwi/sparql/testgeosparql/rcc8tpp.sparql    |  35 --
 .../kiwi/sparql/testgeosparql/rcc8tppi.sparql   |  35 --
 .../kiwi/sparql/testgeosparql/relate.sparql     |  35 --
 .../kiwi/sparql/testgeosparql/sfContains.sparql |  35 --
 .../kiwi/sparql/testgeosparql/sfCrosses.sparql  |  35 --
 .../kiwi/sparql/testgeosparql/sfDisjoint.sparql |  35 --
 .../kiwi/sparql/testgeosparql/sfEquals.sparql   |  34 --
 .../sparql/testgeosparql/sfIntersects.sparql    |  35 --
 .../kiwi/sparql/testgeosparql/sfOverlaps.sparql |  35 --
 .../kiwi/sparql/testgeosparql/sfTouches.sparql  |  35 --
 .../kiwi/sparql/testgeosparql/sfWithin.sparql   |  35 --
 .../sparql/testgeosparql/symDifference.sparql   |  33 --
 .../kiwi/sparql/testgeosparql/union.sparql      |  33 --
 libraries/kiwi/pom.xml                          |   1 +
 155 files changed, 7360 insertions(+), 7173 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/b93cdc78/libraries/kiwi/kiwi-geosparql/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-geosparql/pom.xml 
b/libraries/kiwi/kiwi-geosparql/pom.xml
new file mode 100644
index 0000000..f8c706d
--- /dev/null
+++ b/libraries/kiwi/kiwi-geosparql/pom.xml
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.marmotta</groupId>
+        <artifactId>kiwi-parent</artifactId>
+        <version>3.4.0-SNAPSHOT</version>
+        <relativePath>../</relativePath>
+    </parent>
+
+    <artifactId>kiwi-geosparql</artifactId>
+    <name>KiWi Triplestore: GeoSPARQL</name>
+    <description>
+        Extends KiWi to support OGC GeoSPARQL for representing and querying 
geospatial data on the Semantic Web.
+        This module requires to use PostgreSQL as backend for KiWi, with the 
PostGIS extension enabled.
+    </description>
+    <url>https://wiki.apache.org/marmotta/GSoC/2015/MARMOTTA-584</url>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <!-- No License-Header in META-INF/services -->
+                        
<exclude>src/main/resources/META-INF/services/*</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.marmotta</groupId>
+            <artifactId>kiwi-sparql</artifactId>
+        </dependency>
+
+        <!-- Testing -->
+        <dependency>
+            <artifactId>junit</artifactId>
+            <groupId>junit</groupId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.marmotta</groupId>
+            <artifactId>kiwi-triplestore</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <artifactId>hamcrest-core</artifactId>
+            <groupId>org.hamcrest</groupId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <artifactId>hamcrest-library</artifactId>
+            <groupId>org.hamcrest</groupId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.postgresql</groupId>
+            <artifactId>postgresql</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <scope>test</scope>
+            <optional>true</optional> <!-- GPL licensed, no dependency -->
+        </dependency>
+        <dependency>
+            <groupId>org.openrdf.sesame</groupId>
+            <artifactId>sesame-sail-memory</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.openrdf.sesame</groupId>
+            <artifactId>sesame-rio-api</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.openrdf.sesame</groupId>
+            <artifactId>sesame-rio-rdfxml</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-collections</groupId>
+            <artifactId>commons-collections</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.openrdf.sesame</groupId>
+            <artifactId>sesame-sparql-testsuite</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/marmotta/blob/b93cdc78/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BoundaryFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BoundaryFunction.java
 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BoundaryFunction.java
new file mode 100644
index 0000000..e2f6874
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BoundaryFunction.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.sparql.geosparql;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.sparql.builder.ValueType;
+import org.apache.marmotta.kiwi.sparql.function.NativeFunction;
+import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
+
+/**
+ * A SPARQL function for doing a boundary of a geometry. Should be implemented
+ * directly in the database, as the in-memory implementation is non-functional.
+ * Only support by postgres - POSTGIS
+ * <p/>
+ * The function can be called either as:
+ * <ul>
+ *      <li>geof:boundary(?geometry) </li>
+ * </ul>
+ * Its necesary enable postgis in your database with the next command "CREATE
+ * EXTENSION postgis;" Note that for performance reasons it might be 
preferrable
+ * to create a geometry index for your database. Please consult your database
+ * documentation on how to do this.
+ *
+ * @author Xavier Sumba ([email protected]))
+ */
+public class BoundaryFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.BOUNDARY.toString())) {
+            FunctionRegistry.getInstance().add(new BoundaryFunction());
+        }
+    }
+
+    @Override
+    public Value evaluate(ValueFactory valueFactory, Value... args) throws 
ValueExprEvaluationException {
+        throw new UnsupportedOperationException("cannot evaluate in-memory, 
needs to be supported by the database");
+    }
+
+    @Override
+    public String getURI() {
+        return FN_GEOSPARQL.BOUNDARY.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 1) {
+                String geom1 = args[0];
+                String SRID_default = "4326";
+                /*
+                 * The following condition is required to read WKT  inserted 
directly into args[0] and create a geometries with SRID
+                 * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON 
conditions: 
+                 *   example: geof:buffer("POLYGON(( -7 43, -2 43, -2 38, -7 
38, -7 43))"^^geo:wktLiteral)
+                 * st_AsText condition: It is to use the geometry that is the 
result of another function geosparql.
+                 *   example: geof:buffer(geof:convexhull(?geom))
+                 */
+                if (args[0].contains("POINT") || 
args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || 
args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || 
args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) {
+                    geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], 
SRID_default);
+                }
+                return String.format("ST_AsText(ST_Boundary(%s)) ", geom1);
+            }
+        }
+        throw new UnsupportedOperationException("Boundary function not 
supported by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 1;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/b93cdc78/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BufferFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BufferFunction.java
 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BufferFunction.java
new file mode 100644
index 0000000..b5d69e4
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/BufferFunction.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.sparql.geosparql;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.sparql.builder.ValueType;
+import org.apache.marmotta.kiwi.sparql.function.NativeFunction;
+import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
+
+/**
+ * A SPARQL function for doing a buffer of a geometry. Should be implemented
+ * directly in the database, as the in-memory implementation is non-functional.
+ * Only support by postgres - POSTGIS
+ * <p/>
+ * The function can be called either as:
+ * <ul>
+ *      <li>geof:buffer(?geometryA, radius, unit) </li>
+ * </ul>
+ * Its necesary enable postgis in your database with the next command "CREATE
+ * EXTENSION postgis;" Note that for performance reasons it might be 
preferrable
+ * to create a geometry index for your database. Please consult your database
+ * documentation on how to do this.
+ *
+ * @author Xavier Sumba ([email protected]))
+ */
+public class BufferFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.BUFFER.toString())) {
+            FunctionRegistry.getInstance().add(new BufferFunction());
+        }
+    }
+
+    @Override
+    public Value evaluate(ValueFactory valueFactory, Value... args) throws 
ValueExprEvaluationException {
+        throw new UnsupportedOperationException("cannot evaluate in-memory, 
needs to be supported by the database");
+    }
+
+    @Override
+    public String getURI() {
+        return FN_GEOSPARQL.BUFFER.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 3) {
+                String geom1 = args[0];
+                String SRID_default = "4326";
+                /*
+                 * The following condition is required to read WKT  inserted 
directly into args[0] and create a geometries with SRID
+                 * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON 
conditions: 
+                 *   example: geof:buffer("POLYGON(( -7 43, -2 43, -2 38, -7 
38, -7 43))"^^geo:wktLiteral)
+                 * st_AsText condition: It is to use the geometry that is the 
result of another function geosparql.
+                 *   example: geof:buffer(geof:convexhull(?geom))
+                 */
+                if (args[0].contains("POINT") || 
args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || 
args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || 
args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) {
+                    geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], 
SRID_default);
+                }
+                if (args[2].equalsIgnoreCase("'" + 
FN_GEOSPARQL.meter.toString() + "'") || args[2].equalsIgnoreCase("'" + 
FN_GEOSPARQL.metre.toString() + "'")) {
+                    return String.format("ST_AsText(ST_Transform(ST_Buffer( 
ST_Transform( %s ,26986), %s),4326))", geom1, args[1]);
+                }
+                if (args[2].equalsIgnoreCase("'" + 
FN_GEOSPARQL.degree.toString() + "'")) {
+                    return String.format("ST_AsText(ST_Buffer(%s, %s))", 
geom1, args[1]);
+                }
+                if (args[2].equalsIgnoreCase("'" + 
FN_GEOSPARQL.radian.toString() + "'")) {
+                    return String.format("ST_AsText(ST_Buffer(%s, 
DEGREES(%s)))", geom1, args[1]);
+                }
+            }
+        }
+        throw new UnsupportedOperationException("Buffer function not supported 
by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 3;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 3;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/b93cdc78/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/ConvexHullFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/ConvexHullFunction.java
 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/ConvexHullFunction.java
new file mode 100644
index 0000000..c1fc8b8
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/ConvexHullFunction.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.sparql.geosparql;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.sparql.builder.ValueType;
+import org.apache.marmotta.kiwi.sparql.function.NativeFunction;
+import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
+
+/**
+ * A SPARQL function for doing a convexHull o a geometry. Should be implemented
+ * directly in the database, as the in-memory implementation is non-functional.
+ * Only support by postgres - POSTGIS
+ * <p/>
+ * The function can be called either as:
+ * <ul>
+ *      <li>geof:convexHull(?geometryA) </li>
+ * </ul>
+ * Its necesary enable postgis in your database with the next command "CREATE
+ * EXTENSION postgis;" Note that for performance reasons it might be 
preferrable
+ * to create a geometry index for your database. Please consult your database
+ * documentation on how to do this.
+ *
+ * @author Xavier Sumba ([email protected]))
+ */
+public class ConvexHullFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.CONVEX_HULL.toString())) {
+            FunctionRegistry.getInstance().add(new ConvexHullFunction());
+        }
+    }
+
+    @Override
+    public Value evaluate(ValueFactory valueFactory, Value... args) throws 
ValueExprEvaluationException {
+        throw new UnsupportedOperationException("cannot evaluate in-memory, 
needs to be supported by the database");
+    }
+
+    @Override
+    public String getURI() {
+        return FN_GEOSPARQL.CONVEX_HULL.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 1) {
+                String geom1 = args[0];
+                String SRID_default = "4326";
+                /*
+                 * The following condition is required to read WKT  inserted 
directly into args[0] and create a geometries with SRID
+                 * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON 
conditions: 
+                 *   example: geof:convexHull("POLYGON(( -7 43, -2 43, -2 38, 
-7 38, -7 43))"^^geo:wktLiteral)
+                 * st_AsText condition: It is to use the geometry that is the 
result of another function geosparql.
+                 *   example: geof:convexHull(geof:buffer(?geom, 50, 
units:meter))
+                 */
+                if (args[0].contains("POINT") || 
args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || 
args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || 
args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) {
+                    geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], 
SRID_default);
+                }
+                return String.format("ST_AsText(st_convexHull(%s))", geom1);
+            }
+        }
+        throw new UnsupportedOperationException("ConvexHull function not 
supported by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg
+    ) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 1;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/b93cdc78/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DifferenceFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DifferenceFunction.java
 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DifferenceFunction.java
new file mode 100644
index 0000000..58cd73d
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DifferenceFunction.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.sparql.geosparql;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.sparql.builder.ValueType;
+import org.apache.marmotta.kiwi.sparql.function.NativeFunction;
+import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
+
+/**
+ * A SPARQL function for doing a difference of a geometry. Should be 
implemented
+ * directly in the database, as the in-memory implementation is non-functional.
+ * Only support by postgres - POSTGIS
+ * <p/>
+ * The function can be called either as:
+ * <ul>
+ *      <li>geof:difference(?geometryA, ?geometryB) </li>
+ * </ul>
+ * Its necesary enable postgis in your database with the next command "CREATE
+ * EXTENSION postgis;" Note that for performance reasons it might be 
preferrable
+ * to create a geometry index for your database. Please consult your database
+ * documentation on how to do this.
+ *
+ * @author Xavier Sumba ([email protected]))
+ */
+public class DifferenceFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.DIFFERENCE.toString())) {
+            FunctionRegistry.getInstance().add(new DifferenceFunction());
+        }
+    }
+
+    @Override
+    public Value evaluate(ValueFactory valueFactory, Value... args) throws 
ValueExprEvaluationException {
+        throw new UnsupportedOperationException("cannot evaluate in-memory, 
needs to be supported by the database");
+    }
+
+    @Override
+    public String getURI() {
+        return FN_GEOSPARQL.DIFFERENCE.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 2) {
+                String geom1 = args[0];
+                String geom2 = args[1];
+                String SRID_default = "4326";
+                /*
+                 * The following condition is required to read WKT  inserted 
directly into args[0] or args[1] and create a geometries with SRID
+                 * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON 
conditions: 
+                 *   example: geof:difference(?geom1, "POLYGON(( -7 43, -2 43, 
-2 38, -7 38, -7 43))"^^geo:wktLiteral)
+                 * st_AsText condition: It is to use the geometry that is the 
result of another function geosparql.
+                 *   example: geof:difference(?geom1, geof:buffer(?geometry, 
50, units:meter))
+                 */
+                if (args[0].contains("POINT") || 
args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || 
args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || 
args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) {
+                    geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], 
SRID_default);
+                }
+                if (args[1].contains("POINT") || 
args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || 
args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || 
args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) {
+                    geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], 
SRID_default);
+                }
+                return String.format("ST_AsText(ST_Difference(%s , %s )) ", 
geom1, geom2);
+            }
+        }
+        throw new UnsupportedOperationException("Difference function not 
supported by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg
+    ) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 2;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/b93cdc78/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DistanceFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DistanceFunction.java
 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DistanceFunction.java
new file mode 100644
index 0000000..8a618be
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/DistanceFunction.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.sparql.geosparql;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.sparql.builder.ValueType;
+import org.apache.marmotta.kiwi.sparql.function.NativeFunction;
+import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
+
+/**
+ * Returns the shortest distance in units between any two Points of two
+ * geometries. Should be implemented directly in the database, as the in-memory
+ * implementation is non-functional. Only support by postgres - POSTGIS
+ * <p/>
+ * The function can be called either as:
+ * <ul>
+ *      <li>geof:distance(?geometryA, ?geometryB, units:meter) </li>
+ * </ul>
+ * Its necesary enable postgis in your database with the next command "CREATE
+ * EXTENSION postgis;" Note that for performance reasons it might be 
preferrable
+ * to create a geometry index for your database. Please consult your database
+ * documentation on how to do this.
+ *
+ * @author Xavier Sumba ([email protected]))
+ */
+public class DistanceFunction implements NativeFunction {
+// auto-register for SPARQL environment
+
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.DISTANCE.toString())) {
+            FunctionRegistry.getInstance().add(new DistanceFunction());
+        }
+    }
+
+    @Override
+    public Value evaluate(ValueFactory valueFactory, Value... args) throws 
ValueExprEvaluationException {
+        throw new UnsupportedOperationException("cannot evaluate in-memory, 
needs to be supported by the database");
+    }
+
+    @Override
+    public String getURI() {
+        return FN_GEOSPARQL.DISTANCE.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 3) {
+                String geom1 = args[0];
+                String geom2 = args[1];
+                String SRID_default = "4326";
+                /*
+                 * The following condition is required to read WKT  inserted 
directly into args[0] or args[1] and create a geometries with SRID
+                 * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON 
conditions: 
+                 *   example: geof:distance(?geom1, "POLYGON(( -7 43, -2 43, 
-2 38, -7 38, -7 43))"^^geo:wktLiteral)
+                 * st_AsText condition: It is to use the geometry that is the 
result of another function geosparql.
+                 *   example: geof:distance(?geom1, geof:buffer(?geom2, 50, 
units:meter))
+                 */
+                if (args[0].contains("POINT") || 
args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || 
args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || 
args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) {
+                    geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], 
SRID_default);
+                }
+                if (args[1].contains("POINT") || 
args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || 
args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || 
args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) {
+                    geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], 
SRID_default);
+                }
+                if (args[2].equalsIgnoreCase("'" + 
FN_GEOSPARQL.meter.toString() + "'") || args[2].equalsIgnoreCase("'" + 
FN_GEOSPARQL.metre.toString() + "'")) {
+                    return String.format("ST_Distance( ST_Transform( %s 
,26986), ST_Transform( %s ,26986))", geom1, geom2);
+                }
+                if (args[2].equalsIgnoreCase("'" + 
FN_GEOSPARQL.degree.toString() + "'")) {
+                    return String.format("ST_Distance(%s, %s)", geom1, geom2);
+                }
+                if (args[2].equalsIgnoreCase("'" + 
FN_GEOSPARQL.radian.toString() + "'")) {
+                    return String.format("RADIANS(ST_Distance(%s, %s))", 
geom1, geom2);
+                }
+            }
+        }
+        throw new UnsupportedOperationException("Distance function not 
supported by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.DOUBLE;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 3;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 3;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/b93cdc78/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhContainsFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhContainsFunction.java
 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhContainsFunction.java
new file mode 100644
index 0000000..8bf7581
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhContainsFunction.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.sparql.geosparql;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.sparql.builder.ValueType;
+import org.apache.marmotta.kiwi.sparql.function.NativeFunction;
+import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
+
+/**
+ * A SPARQL function for analyze the Contains Relate between two geometries.
+ * Should be implemented directly in the database, as the in-memory
+ * implementation is non-functional. Only support by postgres - POSTGIS
+ * <p/>
+ * The function can be called either as:
+ * <ul>
+ *      <li>geof:ehContains(?geometryA, ?geometryB) </li>
+ * </ul>
+ * Contains Relate is calculated with "DE-9IM Intersection Pattern": defined in
+ * "RCC8 Query Functions Table 6" from "DE-9IM Intersection Pattern" from OGC
+ * GEOSPARQL DOCUMENT (
+ * https://portal.opengeospatial.org/files/?artifact_id=47664 )
+ *
+ * @author Xavier Sumba ([email protected]))
+ */
+public class EhContainsFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_CONTAINS.toString())) {
+            FunctionRegistry.getInstance().add(new EhContainsFunction());
+        }
+    }
+
+    @Override
+    public Value evaluate(ValueFactory valueFactory, Value... args) throws 
ValueExprEvaluationException {
+        throw new UnsupportedOperationException("cannot evaluate in-memory, 
needs to be supported by the database");
+    }
+
+    @Override
+    public String getURI() {
+        return FN_GEOSPARQL.EH_CONTAINS.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 2) {
+                String geom1 = args[0];
+                String geom2 = args[1];
+                String SRID_default = "4326";
+                /*
+                 * The following condition is required to read WKT  inserted 
directly into args[0] or args[1] and create a geometries with SRID
+                 * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON 
conditions: 
+                 *   example: geof:ehContains(?geom1, "POLYGON(( -7 43, -2 43, 
-2 38, -7 38, -7 43))"^^geo:wktLiteral)
+                 * st_AsText condition: It is to use the geometry that is the 
result of another function geosparql.
+                 *   example: geof:ehContains(?geom1, geof:buffer(?geom2, 50, 
units:meter))
+                 */
+                if (args[0].contains("POINT") || 
args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || 
args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || 
args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) {
+                    geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], 
SRID_default);
+                }
+                if (args[1].contains("POINT") || 
args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || 
args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || 
args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) {
+                    geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], 
SRID_default);
+                }
+                return String.format("ST_Relate(%s, %s, 'T*TFF*FF*')", geom1, 
geom2);
+            }
+        }
+        throw new UnsupportedOperationException("ehContains function not 
supported by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.BOOL;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 2;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/b93cdc78/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoveredByFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoveredByFunction.java
 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoveredByFunction.java
new file mode 100644
index 0000000..b652497
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoveredByFunction.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.sparql.geosparql;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.sparql.builder.ValueType;
+import org.apache.marmotta.kiwi.sparql.function.NativeFunction;
+import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
+
+/**
+ * A SPARQL function for analyze the CoveredBy Relate between two geometries.
+ * Should be implemented directly in the database, as the in-memory
+ * implementation is non-functional. Only support by postgres - POSTGIS
+ * <p/>
+ * The function can be called either as:
+ * <ul>
+ *      <li>geof:ehCoveredBy(?geometryA, ?geometryB) </li>
+ * </ul>
+ * CoveredBy Relate is calculated with "DE-9IM Intersection Pattern": defined 
in
+ * "RCC8 Query Functions Table 7" from "DE-9IM Intersection Pattern" from OGC
+ * GEOSPARQL DOCUMENT (
+ * https://portal.opengeospatial.org/files/?artifact_id=47664 )
+ *
+ * @author Xavier Sumba ([email protected]))
+ */
+public class EhCoveredByFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_COVEREDBY.toString())) {
+            FunctionRegistry.getInstance().add(new EhCoveredByFunction());
+        }
+    }
+
+    @Override
+    public Value evaluate(ValueFactory valueFactory, Value... args) throws 
ValueExprEvaluationException {
+        throw new UnsupportedOperationException("cannot evaluate in-memory, 
needs to be supported by the database");
+    }
+
+    @Override
+    public String getURI() {
+        return FN_GEOSPARQL.EH_COVEREDBY.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 2) {
+                String geom1 = args[0];
+                String geom2 = args[1];
+                String SRID_default = "4326";
+                /*
+                 * The following condition is required to read WKT  inserted 
directly into args[0] or args[1] and create a geometries with SRID
+                 * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON 
conditions: 
+                 *   example: geof:ehCoveredBy(?geom1, "POLYGON(( -7 43, -2 
43, -2 38, -7 38, -7 43))"^^geo:wktLiteral)
+                 * st_AsText condition: It is to use the geometry that is the 
result of another function geosparql.
+                 *   example: geof:ehCoveredBy(?geom1, geof:buffer(?geom2, 50, 
units:meter))
+                 */
+                if (args[0].contains("POINT") || 
args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || 
args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || 
args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) {
+                    geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], 
SRID_default);
+                }
+                if (args[1].contains("POINT") || 
args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || 
args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || 
args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) {
+                    geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], 
SRID_default);
+                }
+                return String.format("ST_Relate(%s, %s, 'TFF*TFT**')", geom1, 
geom2);
+            }
+        }
+        throw new UnsupportedOperationException("ehCoveredBy function not 
supported by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.BOOL;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 2;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/b93cdc78/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoversFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoversFunction.java
 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoversFunction.java
new file mode 100644
index 0000000..8b13e33
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhCoversFunction.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.sparql.geosparql;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.sparql.builder.ValueType;
+import org.apache.marmotta.kiwi.sparql.function.NativeFunction;
+import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
+
+/**
+ * A SPARQL function for analyze the Covers Relate between two geometries.
+ * Should be implemented directly in the database, as the in-memory
+ * implementation is non-functional. Only support by postgres - POSTGIS
+ * <p/>
+ * The function can be called either as:
+ * <ul>
+ *      <li>geof:ehCovers(?geometryA, ?geometryB) </li>
+ * </ul>
+ * Covers Relate is calculated with "DE-9IM Intersection Pattern": defined in
+ * "RCC8 Query Functions Table 6" from "DE-9IM Intersection Pattern" from OGC
+ * GEOSPARQL DOCUMENT (
+ * https://portal.opengeospatial.org/files/?artifact_id=47664 )
+ *
+ * @author Xavier Sumba ([email protected]))
+ */
+public class EhCoversFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_COVERS.toString())) {
+            FunctionRegistry.getInstance().add(new EhCoversFunction());
+        }
+    }
+
+    @Override
+    public Value evaluate(ValueFactory valueFactory, Value... args) throws 
ValueExprEvaluationException {
+        throw new UnsupportedOperationException("cannot evaluate in-memory, 
needs to be supported by the database");
+    }
+
+    @Override
+    public String getURI() {
+        return FN_GEOSPARQL.EH_COVERS.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 2) {
+                String geom1 = args[0];
+                String geom2 = args[1];
+                String SRID_default = "4326";
+                /*
+                 * The following condition is required to read WKT  inserted 
directly into args[0] or args[1] and create a geometries with SRID
+                 * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON 
conditions: 
+                 *   example: geof:ehCovers(?geom1, "POLYGON(( -7 43, -2 43, 
-2 38, -7 38, -7 43))"^^geo:wktLiteral)
+                 * st_AsText condition: It is to use the geometry that is the 
result of another function geosparql.
+                 *   example: geof:ehCovers(?geom1, geof:buffer(?geom2, 50, 
units:meter))
+                 */
+                if (args[0].contains("POINT") || 
args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || 
args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || 
args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) {
+                    geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], 
SRID_default);
+                }
+                if (args[1].contains("POINT") || 
args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || 
args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || 
args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) {
+                    geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], 
SRID_default);
+                }
+                return String.format("ST_Relate(%s, %s, 'T*TFT*FF*')", geom1, 
geom2);
+            }
+        }
+        throw new UnsupportedOperationException("ehCovers function not 
supported by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.BOOL;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 2;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/b93cdc78/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhDisjointFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhDisjointFunction.java
 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhDisjointFunction.java
new file mode 100644
index 0000000..05bb954
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhDisjointFunction.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.sparql.geosparql;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.sparql.builder.ValueType;
+import org.apache.marmotta.kiwi.sparql.function.NativeFunction;
+import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
+
+/**
+ * A SPARQL function for analyze the Disjoint between two geometries. Should be
+ * implemented directly in the database, as the in-memory implementation is
+ * non-functional. Only support by postgres - POSTGIS
+ * <p/>
+ * The function can be called either as:
+ * <ul>
+ *      <li>geof:ehDisjoint(?geometryA, ?geometryB) </li>
+ * </ul>
+ * Disjoint is calculated with "DE-9IM Intersection Pattern": defined in "RCC8
+ * Query Functions Table 6" from "DE-9IM Intersection Pattern" from OGC
+ * GEOSPARQL DOCUMENT (
+ * https://portal.opengeospatial.org/files/?artifact_id=47664 )
+ *
+ * @author Xavier Sumba ([email protected]))
+ */
+public class EhDisjointFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_DISJOINT.toString())) {
+            FunctionRegistry.getInstance().add(new EhDisjointFunction());
+        }
+    }
+
+    @Override
+    public Value evaluate(ValueFactory valueFactory, Value... args) throws 
ValueExprEvaluationException {
+        throw new UnsupportedOperationException("cannot evaluate in-memory, 
needs to be supported by the database");
+    }
+
+    @Override
+    public String getURI() {
+        return FN_GEOSPARQL.EH_DISJOINT.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 2) {
+                String geom1 = args[0];
+                String geom2 = args[1];
+                String SRID_default = "4326";
+                /*
+                 * The following condition is required to read WKT  inserted 
directly into args[0] or args[1] and create a geometries with SRID
+                 * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON 
conditions: 
+                 *   example: geof:ehDisjoint(?geom1, "POLYGON(( -7 43, -2 43, 
-2 38, -7 38, -7 43))"^^geo:wktLiteral)
+                 * st_AsText condition: It is to use the geometry that is the 
result of another function geosparql.
+                 *   example: geof:ehDisjoint(?geom1, geof:buffer(?geom2, 50, 
units:meter))
+                 */
+                if (args[0].contains("POINT") || 
args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || 
args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || 
args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) {
+                    geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], 
SRID_default);
+                }
+                if (args[1].contains("POINT") || 
args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || 
args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || 
args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) {
+                    geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], 
SRID_default);
+                }
+                return String.format("ST_Relate(%s, %s, 'FF*FF****')", geom1, 
geom2);
+            }
+        }
+        throw new UnsupportedOperationException("ehDisjoint function not 
supported by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.BOOL;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 2;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/b93cdc78/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhEqualsFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhEqualsFunction.java
 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhEqualsFunction.java
new file mode 100644
index 0000000..515f7c3
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhEqualsFunction.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.sparql.geosparql;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.sparql.builder.ValueType;
+import org.apache.marmotta.kiwi.sparql.function.NativeFunction;
+import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
+
+/**
+ * A SPARQL function for analyze the EhEquals between two geometries. Should be
+ * implemented directly in the database, as the in-memory implementation is
+ * non-functional. Only support by postgres - POSTGIS
+ * <p/>
+ * The function can be called either as:
+ * <ul>
+ *      <li>geof:ehEquals(?geometryA, ?geometryB) </li>
+ * </ul>
+ * EhEquals is calculated with "DE-9IM Intersection Pattern": defined in "RCC8
+ * Query Functions Table 6" from "DE-9IM Intersection Pattern" from OGC
+ * GEOSPARQL DOCUMENT (
+ * https://portal.opengeospatial.org/files/?artifact_id=47664 )
+ *
+ * @author Xavier Sumba ([email protected]))
+ */
+public class EhEqualsFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_EQUALS.toString())) {
+            FunctionRegistry.getInstance().add(new EhEqualsFunction());
+        }
+    }
+
+    @Override
+    public Value evaluate(ValueFactory valueFactory, Value... args) throws 
ValueExprEvaluationException {
+        throw new UnsupportedOperationException("cannot evaluate in-memory, 
needs to be supported by the database");
+    }
+
+    @Override
+    public String getURI() {
+        return FN_GEOSPARQL.EH_EQUALS.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 2) {
+                String geom1 = args[0];
+                String geom2 = args[1];
+                String SRID_default = "4326";
+                /*
+                 * The following condition is required to read WKT  inserted 
directly into args[0] or args[1] and create a geometries with SRID
+                 * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON 
conditions: 
+                 *   example: geof:ehEquals(?geom1, "POLYGON(( -7 43, -2 43, 
-2 38, -7 38, -7 43))"^^geo:wktLiteral)
+                 * st_AsText condition: It is to use the geometry that is the 
result of another function geosparql.
+                 *   example: geof:ehEquals(?geom1, geof:buffer(?geom2, 50, 
units:meter))
+                 */
+                if (args[0].contains("POINT") || 
args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || 
args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || 
args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) {
+                    geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], 
SRID_default);
+                }
+                if (args[1].contains("POINT") || 
args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || 
args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || 
args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) {
+                    geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], 
SRID_default);
+                }
+                return String.format("ST_Relate(%s, %s, 'TFFFTFFFT')", geom1, 
geom2);
+            }
+        }
+        throw new UnsupportedOperationException("ehEquals function not 
supported by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.BOOL;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 2;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/b93cdc78/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhInsideFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhInsideFunction.java
 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhInsideFunction.java
new file mode 100644
index 0000000..0ca7c11
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/EhInsideFunction.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.sparql.geosparql;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.sparql.builder.ValueType;
+import org.apache.marmotta.kiwi.sparql.function.NativeFunction;
+import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
+
+/**
+ * A SPARQL function for analyze the Inside Relate between two geometries.
+ * Should be implemented directly in the database, as the in-memory
+ * implementation is non-functional. Only support by postgres - POSTGIS
+ * <p/>
+ * The function can be called either as:
+ * <ul>
+ *      <li>geof:ehInside(?geometryA, ?geometryB) </li>
+ * </ul>
+ * Inside Relate is calculated with "DE-9IM Intersection Pattern": defined in
+ * "RCC8 Query Functions Table 6" from "DE-9IM Intersection Pattern" from OGC
+ * GEOSPARQL DOCUMENT (
+ * https://portal.opengeospatial.org/files/?artifact_id=47664 )
+ *
+ * @author Xavier Sumba ([email protected]))
+ */
+public class EhInsideFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.EH_INSIDE.toString())) {
+            FunctionRegistry.getInstance().add(new EhInsideFunction());
+        }
+    }
+
+    @Override
+    public Value evaluate(ValueFactory valueFactory, Value... args) throws 
ValueExprEvaluationException {
+        throw new UnsupportedOperationException("cannot evaluate in-memory, 
needs to be supported by the database");
+    }
+
+    @Override
+    public String getURI() {
+        return FN_GEOSPARQL.EH_INSIDE.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 2) {
+                String geom1 = args[0];
+                String geom2 = args[1];
+                String SRID_default = "4326";
+                /*
+                 * The following condition is required to read WKT  inserted 
directly into args[0] or args[1] and create a geometries with SRID
+                 * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON 
conditions: 
+                 *   example: geof:ehInside(?geom, "POLYGON(( -7 43, -2 43, -2 
38, -7 38, -7 43))"^^geo:wktLiteral)
+                 * st_AsText condition: It is to use the geometry that is the 
result of another function geosparql.
+                 *   example: geof:ehInside(?geom, geof:buffer(?geom2, 50, 
units:meter))
+                 */
+                if (args[0].contains("POINT") || 
args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || 
args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || 
args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) {
+                    geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], 
SRID_default);
+                }
+                if (args[1].contains("POINT") || 
args[1].contains("MULTIPOINT") || args[1].contains("LINESTRING") || 
args[1].contains("MULTILINESTRING") || args[1].contains("POLYGON") || 
args[1].contains("MULTIPOLYGON") || args[1].contains("ST_AsText")) {
+                    geom2 = String.format("ST_GeomFromText(%s,%s)", args[1], 
SRID_default);
+                }
+                return String.format("ST_Relate(%s, %s, 'TFF*FFT**')", geom1, 
geom2);
+            }
+        }
+        throw new UnsupportedOperationException("ehInside function not 
supported by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.BOOL;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 2;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 2;
+    }
+}

Reply via email to