This is an automated email from the ASF dual-hosted git repository.
jsorel pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new f2df1ad Filter : support raw crs in ST_Transform, implement
SimpleQuery.toString
f2df1ad is described below
commit f2df1ad651798cec5cdce2a49207de67c570b3c7
Author: jsorel <[email protected]>
AuthorDate: Thu Jul 11 17:23:16 2019 +0200
Filter : support raw crs in ST_Transform, implement SimpleQuery.toString
---
.../java/org/apache/sis/filter/ST_Transform.java | 23 ++++++---
.../test/java/org/apache/sis/filter/SQLMMTest.java | 31 ++++++++----
.../sis/internal/storage/query/SimpleQuery.java | 55 ++++++++++++++++++----
3 files changed, 86 insertions(+), 23 deletions(-)
diff --git
a/core/sis-feature/src/main/java/org/apache/sis/filter/ST_Transform.java
b/core/sis-feature/src/main/java/org/apache/sis/filter/ST_Transform.java
index 89995e9..790dc45 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/filter/ST_Transform.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/filter/ST_Transform.java
@@ -53,13 +53,24 @@ final class ST_Transform extends AbstractFunction
implements FeatureExpression {
if (!(parameters[1] instanceof Literal)) {
throw new IllegalArgumentException("Second expression must be a
Literal");
}
- final String crsCode = parameters[1].evaluate(null, String.class);
- try {
- this.outCrs = CRS.forCode(crsCode);
- } catch (FactoryException ex) {
- throw new IllegalArgumentException("Requested CRS" + crsCode + "is
undefined.\n"+ex.getMessage(), ex);
+ final Object crsObj = parameters[1].evaluate(null);
+ if (crsObj instanceof CoordinateReferenceSystem) {
+ outCrs = (CoordinateReferenceSystem) crsObj;
+ } else if (crsObj instanceof Number) {
+ try {
+ this.outCrs = CRS.forCode("EPSG:" + crsObj);
+ } catch (FactoryException ex) {
+ throw new IllegalArgumentException("Requested CRS" + crsObj +
"is undefined.\n"+ex.getMessage(), ex);
+ }
+ } else if (crsObj instanceof String) {
+ try {
+ this.outCrs = CRS.forCode((String) crsObj);
+ } catch (FactoryException ex) {
+ throw new IllegalArgumentException("Requested CRS" + crsObj +
"is undefined.\n"+ex.getMessage(), ex);
+ }
+ } else {
+ throw new IllegalArgumentException("Second expression must be a
Literal with a CRS, Number or String value");
}
-
}
@Override
diff --git
a/core/sis-feature/src/test/java/org/apache/sis/filter/SQLMMTest.java
b/core/sis-feature/src/test/java/org/apache/sis/filter/SQLMMTest.java
index 5f27152..d6ec945 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/filter/SQLMMTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/filter/SQLMMTest.java
@@ -53,6 +53,7 @@ public class SQLMMTest extends TestCase {
//test invalid
try {
factory.function("ST_Transform");
+ Assert.fail("Creation with no argument should fail");
} catch (IllegalArgumentException ex) {
//ok
}
@@ -67,17 +68,29 @@ public class SQLMMTest extends TestCase {
final Feature feature = type.newInstance();
feature.setPropertyValue("geom", geometry);
- //transform function
- final Function fct = factory.function("ST_Transform",
factory.property("geom"), factory.literal("EPSG:4326"));
+ { //test transform function using epsg code
+ final Function fct = factory.function("ST_Transform",
factory.property("geom"), factory.literal("EPSG:4326"));
- //check result
- final Object newGeom = fct.evaluate(feature);
- Assert.assertTrue(newGeom instanceof Point);
- final Point trs = (Point) newGeom;
- Assert.assertEquals(outCrs, trs.getUserData());
- Assert.assertEquals(30.0, trs.getX(), 0.0);
- Assert.assertEquals(10.0, trs.getY(), 0.0);
+ //check result
+ final Object newGeom = fct.evaluate(feature);
+ Assert.assertTrue(newGeom instanceof Point);
+ final Point trs = (Point) newGeom;
+ Assert.assertEquals(outCrs, trs.getUserData());
+ Assert.assertEquals(30.0, trs.getX(), 0.0);
+ Assert.assertEquals(10.0, trs.getY(), 0.0);
+ }
+
+ { //test transform function using crs object
+ final Function fct = factory.function("ST_Transform",
factory.property("geom"), factory.literal(outCrs));
+ //check result
+ final Object newGeom = fct.evaluate(feature);
+ Assert.assertTrue(newGeom instanceof Point);
+ final Point trs = (Point) newGeom;
+ Assert.assertEquals(outCrs, trs.getUserData());
+ Assert.assertEquals(30.0, trs.getX(), 0.0);
+ Assert.assertEquals(10.0, trs.getY(), 0.0);
+ }
}
diff --git
a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java
index b4eaa62..17d6912 100644
---
a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java
+++
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java
@@ -19,7 +19,7 @@ package org.apache.sis.internal.storage.query;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
-import org.opengis.util.GenericName;
+import java.util.StringJoiner;
import org.apache.sis.feature.builder.FeatureTypeBuilder;
import org.apache.sis.internal.feature.FeatureExpression;
import org.apache.sis.internal.util.UnmodifiableArrayList;
@@ -29,15 +29,14 @@ import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.Classes;
import org.apache.sis.util.iso.Names;
import org.apache.sis.util.resources.Errors;
-
-// Branch-dependent imports
-import org.opengis.filter.Filter;
-import org.opengis.filter.sort.SortBy;
-import org.opengis.filter.expression.Expression;
-import org.opengis.feature.FeatureType;
-import org.opengis.feature.PropertyType;
import org.opengis.feature.AttributeType;
import org.opengis.feature.FeatureAssociationRole;
+import org.opengis.feature.FeatureType;
+import org.opengis.feature.PropertyType;
+import org.opengis.filter.Filter;
+import org.opengis.filter.expression.Expression;
+import org.opengis.filter.sort.SortBy;
+import org.opengis.util.GenericName;
/**
@@ -353,6 +352,7 @@ public class SimpleQuery extends Query {
if (alias != null) {
b.append('"').append(alias).append('"');
}
+ b.append(" = ").append(expression.getClass().getSimpleName());
return b.append(']').toString();
}
}
@@ -420,4 +420,43 @@ public class SimpleQuery extends Query {
}
return true;
}
+
+ /**
+ * Display a text representation looking like an SQL Select query.
+ *
+ * @return text representation
+ */
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("SELECT ");
+ if (columns != null) {
+ final StringJoiner sj = new StringJoiner(", ");
+ for (Column col : columns) {
+ sj.add(col.toString());
+ }
+ sb.append(sj.toString());
+ }
+ if (filter != null && filter != Filter.INCLUDE) {
+ sb.append(" WHERE ").append(filter);
+ }
+ if (sortBy != null && sortBy != SortBy.UNSORTED) {
+ sb.append(" ORDER BY ");
+ final StringJoiner sj = new StringJoiner(", ");
+ for (SortBy s : sortBy) {
+ sj.add(s.toString());
+ }
+ sb.append(sj.toString());
+ }
+ if (limit != UNLIMITED) {
+ sb.append(" LIMIT ").append(limit);
+ }
+ if (skip != 0) {
+ sb.append(" OFFSET ").append(limit);
+ }
+
+ return sb.toString();
+ }
+
+
}