http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SymDifferenceFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SymDifferenceFunction.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SymDifferenceFunction.java
new file mode 100644
index 0000000..2d40870
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/SymDifferenceFunction.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.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 symDifference 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:symDifference(?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 SymDifferenceFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SYM_DIFFERENCE.toString())) {
+            FunctionRegistry.getInstance().add(new SymDifferenceFunction());
+        }
+    }
+
+    @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.SYM_DIFFERENCE.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 2) {
+                if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || 
args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || 
args[1].contains(FN_GEOSPARQL.POINT)) {  //If users insert Direct the WKT  
Geometry 
+                    return String.format("ST_AsText(ST_SymDifference(%s , %s 
))", args[0], args[1]);
+                }
+                return String.format("ST_AsText(ST_SymDifference(%s , %s )) ", 
args[0], args[1]);
+            }
+        }
+        throw new UnsupportedOperationException("symDifference function not 
supported by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 2;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/UnionFunction.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/UnionFunction.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/UnionFunction.java
new file mode 100644
index 0000000..3c274d4
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/geosparql/UnionFunction.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.sparql.function.geosparql;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.sparql.builder.ValueType;
+import org.apache.marmotta.kiwi.sparql.function.NativeFunction;
+import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
+
+/**
+ * A SPARQL function for doing a union 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:union(?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 UnionFunction implements NativeFunction {
+
+    // auto-register for SPARQL environment
+    static {
+        if 
(!FunctionRegistry.getInstance().has(FN_GEOSPARQL.UNION.toString())) {
+            FunctionRegistry.getInstance().add(new UnionFunction());
+        }
+    }
+
+    @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.UNION.toString();
+    }
+
+    /**
+     * Return true if this function has available native support for the given
+     * dialect
+     *
+     * @param dialect
+     * @return
+     */
+    @Override
+    public boolean isSupported(KiWiDialect dialect) {
+        return dialect instanceof PostgreSQLDialect;
+    }
+
+    /**
+     * Return a string representing how this GeoSPARQL function is translated
+     * into SQL ( Postgis Function ) in the given dialect
+     *
+     * @param dialect
+     * @param args
+     * @return
+     */
+    @Override
+    public String getNative(KiWiDialect dialect, String... args) {
+        if (dialect instanceof PostgreSQLDialect) {
+            if (args.length == 2) {
+                if (args[1].contains(FN_GEOSPARQL.MULTIPOLYGON) || 
args[1].contains(FN_GEOSPARQL.MULTILINESTRING) || 
args[1].contains(FN_GEOSPARQL.POINT)) {  //If users insert Direct the WKT  
Geometry 
+                    return String.format("ST_AsText(ST_Union(%s , %s ) )", 
args[0], args[1]);
+                }
+                return String.format("ST_AsText(ST_Union(%s , %s ) )", 
args[0], args[1]);
+            }
+
+        }
+        throw new UnsupportedOperationException("union function not supported 
by dialect " + dialect);
+    }
+
+    /**
+     * Get the return type of the function. This is needed for SQL type casting
+     * inside KiWi.
+     *
+     * @return
+     */
+    @Override
+    public ValueType getReturnType() {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Get the argument type of the function for the arg'th argument (starting
+     * to count at 0). This is needed for SQL type casting inside KiWi.
+     *
+     * @param arg
+     * @return
+     */
+    @Override
+    public ValueType getArgumentType(int arg) {
+        return ValueType.GEOMETRY;
+    }
+
+    /**
+     * Return the minimum number of arguments this function requires.
+     *
+     * @return
+     */
+    @Override
+    public int getMinArgs() {
+        return 2;
+    }
+
+    /**
+     * Return the maximum number of arguments this function can take
+     *
+     * @return
+     */
+    @Override
+    public int getMaxArgs() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-sparql/src/main/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 42d4694..ca8e4cf 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
@@ -23,10 +23,17 @@ 
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.RelateFunction
 
 org.apache.marmotta.kiwi.sparql.function.geosparql.BufferFunction
 org.apache.marmotta.kiwi.sparql.function.geosparql.ConvexHullFunction
 org.apache.marmotta.kiwi.sparql.function.geosparql.IntersectionFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.DistanceFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.DifferenceFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.SymDifferenceFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.EnvelopeFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.BoundaryFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.UnionFunction
 
 org.apache.marmotta.kiwi.sparql.function.cast.NBooleanCast
 org.apache.marmotta.kiwi.sparql.function.cast.NDateTimeCast

http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/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 2d7dac3..b6e3b05 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
@@ -11,7 +11,14 @@ 
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.RelateFunction
 
 org.apache.marmotta.kiwi.sparql.function.geosparql.BufferFunction
 org.apache.marmotta.kiwi.sparql.function.geosparql.ConvexHullFunction
 org.apache.marmotta.kiwi.sparql.function.geosparql.IntersectionFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.DistanceFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.DifferenceFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.SymDifferenceFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.EnvelopeFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.BoundaryFunction
+org.apache.marmotta.kiwi.sparql.function.geosparql.UnionFunction

http://git-wip-us.apache.org/repos/asf/marmotta/blob/0acf49b4/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/vocabulary/FN_GEOSPARQL.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/vocabulary/FN_GEOSPARQL.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/vocabulary/FN_GEOSPARQL.java
index 2e33796..228d8a4 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/vocabulary/FN_GEOSPARQL.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/vocabulary/FN_GEOSPARQL.java
@@ -57,12 +57,27 @@ public class FN_GEOSPARQL {
     public static final URI SF_CROSSES;
     public static final URI SF_DISJOINT;
     public static final URI SF_EQUALS;
-
+    public static final URI RELATE;
+    
     //Non-Topological  FUNCTION 
     public static final URI BUFFER;
     public static final URI CONVEX_HULL;
     public static final URI INTERSECTION;
-    
+    public static final URI DISTANCE;
+    public static final URI UNION;
+    public static final URI DIFFERENCE;
+    public static final URI SYM_DIFFERENCE;
+    public static final URI ENVELOPE;
+    public static final URI BOUNDARY;
+
+    //measure units
+    public static final String unitsNAMESPACE = 
"http://www.opengis.net/def/uom/OGC/1.0/";;
+    public static final String unitsPREFIX = "units";
+
+    public static final Namespace unitsNS = new NamespaceImpl(unitsPREFIX, 
unitsNAMESPACE);
+
+    public static final URI meter;
+
     static {
         ValueFactory f = new ValueFactoryImpl();
 
@@ -70,16 +85,24 @@ public class FN_GEOSPARQL {
         SF_WITHIN = f.createURI(NAMESPACE, "sfWithin");
         SF_TOUCHES = f.createURI(NAMESPACE, "sfTouches");
         SF_CONTAINS = f.createURI(NAMESPACE, "sfContains");
-        SF_OVERLAPS =  f.createURI(NAMESPACE, "sfOverlaps");
+        SF_OVERLAPS = f.createURI(NAMESPACE, "sfOverlaps");
         SF_CROSSES = f.createURI(NAMESPACE, "sfCrosses");
         SF_DISJOINT = f.createURI(NAMESPACE, "sfDisjoint");
         SF_EQUALS = f.createURI(NAMESPACE, "sfEquals");
+        RELATE = f.createURI(NAMESPACE, "relate");
         
-        BUFFER = f.createURI(NAMESPACE,"buffer");
-        CONVEX_HULL = f.createURI(NAMESPACE,"convexHull");
-        INTERSECTION = f.createURI(NAMESPACE,"intersection");
-        
-        
+        BUFFER = f.createURI(NAMESPACE, "buffer");
+        CONVEX_HULL = f.createURI(NAMESPACE, "convexHull");
+        INTERSECTION = f.createURI(NAMESPACE, "intersection");
+        DISTANCE = f.createURI(NAMESPACE, "distance");
+        UNION = f.createURI(NAMESPACE, "union");
+        DIFFERENCE = f.createURI(NAMESPACE, "difference");
+        SYM_DIFFERENCE = f.createURI(NAMESPACE, "symDifference");
+        ENVELOPE = f.createURI(NAMESPACE, "envelope");
+        BOUNDARY = f.createURI(NAMESPACE, "boundary");
+
+        meter = f.createURI(unitsNAMESPACE, "meter");
+
         POINT = "POINT";
         MULTIPOLYGON = "MULTIPOLYGON";
         MULTILINESTRING = "MULTILINESTRING";

Reply via email to