http://git-wip-us.apache.org/repos/asf/marmotta/blob/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfContainsFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfContainsFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfContainsFunction.java deleted file mode 100644 index f9c2811..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfContainsFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for doing a geometry that contains another geometries. - * Should be implemented directly in the database, as the in-memory - * implementation is non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:sfContains(?geometryA, ?geometryB) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class SfContainsFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_CONTAINS.toString())) { - FunctionRegistry.getInstance().add(new SfContainsFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.SF_CONTAINS.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - 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:sfContains(?wkt, "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:sfContains(?wkt, geof:buffer(?wkt2, 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_Contains(%s , %s )", geom1, geom2); - } - } - throw new UnsupportedOperationException("Contains 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/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfCrossesFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfCrossesFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfCrossesFunction.java deleted file mode 100644 index a581629..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfCrossesFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for doing a crosses between two geometries. Should be - * implemented directly in the database, as the in-memory implementation is - * non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:sfCrosses(?geometryA, ?geometryB) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class SfCrossesFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_CROSSES.toString())) { - FunctionRegistry.getInstance().add(new SfCrossesFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.SF_CROSSES.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - 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:sfCrosses(?wkt, "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:sfCrosses(?wkt, geof:buffer(?wkt2, 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_Crosses(%s , %s )", geom1, geom2); - } - } - throw new UnsupportedOperationException("Crosses 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/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfDisjointFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfDisjointFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfDisjointFunction.java deleted file mode 100644 index bbe63e1..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfDisjointFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for doing a Disjoint between two geometries. Should be - * implemented directly in the database, as the in-memory implementation is - * non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:sfDisjoint(?geometryA, ?geometryB) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class SfDisjointFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_DISJOINT.toString())) { - FunctionRegistry.getInstance().add(new SfDisjointFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.SF_DISJOINT.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - 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:sfDisjoint(?wkt, "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:sfDisjoint(?wkt, geof:buffer(?wkt2, 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_Disjoint(%s , %s )", geom1, geom2); - } - } - throw new UnsupportedOperationException("Disjoint 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/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfEqualsFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfEqualsFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfEqualsFunction.java deleted file mode 100644 index eb242f5..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfEqualsFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for doing a equals between two geometries. Should be - * implemented directly in the database, as the in-memory implementation is - * non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:sfEquals(?geometryA, ?geometryB) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class SfEqualsFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_EQUALS.toString())) { - FunctionRegistry.getInstance().add(new SfEqualsFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.SF_EQUALS.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - 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:sfEquals(?wkt, "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:sfEquals(?wkt, geof:buffer(?wkt2, 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_Equals(%s , %s )", geom1, geom2); - } - } - throw new UnsupportedOperationException("Equals 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/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfIntersectsFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfIntersectsFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfIntersectsFunction.java deleted file mode 100644 index e33f6e8..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfIntersectsFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.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 intersection between two geometries. Should be - * implemented directly in the database, as the in-memory implementation is - * non-functional. Only support by postgres - POSTGIS. - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:sfIntersects(?geometryA, ?geometryB) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class SfIntersectsFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_INTERSECTS.toString())) { - FunctionRegistry.getInstance().add(new SfIntersectsFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.SF_INTERSECTS.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - 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:sfIntersects(?wkt, "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:sfIntersects(?wkt, geof:buffer(?wkt2, 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_Intersects(%s , %s ) ", geom1, geom2); - } - } - throw new UnsupportedOperationException("Intersects function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.BOOL; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.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/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfOverlapsFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfOverlapsFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfOverlapsFunction.java deleted file mode 100644 index e34e0f3..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfOverlapsFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for doing a overlaps between geometries. Should be - * implemented directly in the database, as the in-memory implementation is - * non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:sfOverlaps(?geometryA, ?geometryB) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class SfOverlapsFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_OVERLAPS.toString())) { - FunctionRegistry.getInstance().add(new SfOverlapsFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.SF_OVERLAPS.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - 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:sfOverlaps(?wkt, "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:sfOverlaps(?wkt, geof:buffer(?wkt2, 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_Overlaps(%s , %s )", geom1, geom2); - } - } - throw new UnsupportedOperationException("Overlaps 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/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfTouchesFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfTouchesFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfTouchesFunction.java deleted file mode 100644 index 3146c85..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfTouchesFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for doing touches analyzer between two geometries. Should - * be implemented directly in the database, as the in-memory implementation is - * non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:sfTouches(?geometryA, ?geometryB) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class SfTouchesFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_TOUCHES.toString())) { - FunctionRegistry.getInstance().add(new SfTouchesFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.SF_TOUCHES.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - 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:sfTouches(?wkt, "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:sfTouches(?wkt, geof:buffer(?wkt2, 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_Touches(%s , %s )", geom1, geom2); - } - } - throw new UnsupportedOperationException("Touches function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.BOOL; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.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/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfWithinFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfWithinFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfWithinFunction.java deleted file mode 100644 index 3fa8d25..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SfWithinFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.geosparql; - -import org.apache.marmotta.kiwi.persistence.KiWiDialect; -import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect; -import org.apache.marmotta.kiwi.sparql.builder.ValueType; -import org.apache.marmotta.kiwi.sparql.function.NativeFunction; -import org.apache.marmotta.kiwi.vocabulary.FN_GEOSPARQL; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; - -/** - * A SPARQL function for doing a within between two geometries. Should be - * implemented directly in the database, as the in-memory implementation is - * non-functional. Only support by postgres - POSTGIS - * <p/> - * The function can be called either as: - * <ul> - * <li>geof:sfWithin(?geometryA, ?geometryB) </li> - * </ul> - * Its necesary enable postgis in your database with the next command "CREATE - * EXTENSION postgis;" Note that for performance reasons it might be preferrable - * to create a geometry index for your database. Please consult your database - * documentation on how to do this. - * - * @author Xavier Sumba ([email protected])) - */ -public class SfWithinFunction implements NativeFunction { - - // auto-register for SPARQL environment - static { - if (!FunctionRegistry.getInstance().has(FN_GEOSPARQL.SF_WITHIN.toString())) { - FunctionRegistry.getInstance().add(new SfWithinFunction()); - } - } - - @Override - public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { - throw new UnsupportedOperationException("cannot evaluate in-memory, needs to be supported by the database"); - } - - @Override - public String getURI() { - return FN_GEOSPARQL.SF_WITHIN.toString(); - } - - /** - * Return true if this function has available native support for the given - * dialect - * - * @param dialect - * @return - */ - @Override - public boolean isSupported(KiWiDialect dialect) { - return dialect instanceof PostgreSQLDialect; - } - - /** - * Return a string representing how this GeoSPARQL function is translated - * into SQL ( Postgis Function ) in the given dialect - * - * @param dialect - * @param args - * @return - */ - @Override - public String getNative(KiWiDialect dialect, String... args) { - if (dialect instanceof PostgreSQLDialect) { - if (args.length == 2) { - 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:sfWithin(?wkt, "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:sfWithin(?wkt, geof:buffer(?wkt2, 5, units:degree)) - */ - 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_Within(%s,%s)", geom1, geom2); - } - } - throw new UnsupportedOperationException("Within function not supported by dialect " + dialect); - } - - /** - * Get the return type of the function. This is needed for SQL type casting - * inside KiWi. - * - * @return - */ - @Override - public ValueType getReturnType() { - return ValueType.BOOL; - } - - /** - * Get the argument type of the function for the arg'th argument (starting - * to count at 0). This is needed for SQL type casting inside KiWi. - * - * @param arg - * @return - */ - @Override - public ValueType getArgumentType(int arg) { - return ValueType.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/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SymDifferenceFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SymDifferenceFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SymDifferenceFunction.java deleted file mode 100644 index d7ba98c..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/SymDifferenceFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.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) { - 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:symDifference(?wkt, "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:symDifference(?wkt, geof:buffer(?wkt2, 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_SymDifference(%s , %s )) ", geom1, geom2); - } - } - 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/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/UnionFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/UnionFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/UnionFunction.java deleted file mode 100644 index 5086a0f..0000000 --- a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/UnionFunction.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.marmotta.kiwi.sparql.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) { - 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:union(?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:union(?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_AsText(ST_Union(%s , %s ) )", geom1, geom2); - } - } - 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/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/functions/BoundaryFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/functions/BoundaryFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/functions/BoundaryFunction.java new file mode 100644 index 0000000..20a691d --- /dev/null +++ b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/functions/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.functions; + +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/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/functions/BufferFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/functions/BufferFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/functions/BufferFunction.java new file mode 100644 index 0000000..9a4dc23 --- /dev/null +++ b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/functions/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.functions; + +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/df172223/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/functions/ConvexHullFunction.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/functions/ConvexHullFunction.java b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/functions/ConvexHullFunction.java new file mode 100644 index 0000000..0f02805 --- /dev/null +++ b/libraries/kiwi/kiwi-geosparql/src/main/java/org/apache/marmotta/kiwi/sparql/geosparql/functions/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.functions; + +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; + } +}
