sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ama...@apache.org
Subject [sis] 01/02: fix(CQL): fix bbox writing by avoiding deprecated methods.
Date Fri, 15 Nov 2019 16:45:34 GMT
This is an automated email from the ASF dual-hosted git repository.

amanin pushed a commit to branch refactor/sql-store
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 603d5dac3df366a047fefe35ec4b54e18b60d77f
Author: Alexis Manin <amanin@apache.org>
AuthorDate: Fri Nov 15 17:38:49 2019 +0100

    fix(CQL): fix bbox writing by avoiding deprecated methods.
---
 .../org/apache/sis/cql/FilterToCQLVisitor.java     | 42 +++++++++++++++++-----
 .../java/org/apache/sis/filter/DefaultBBOX.java    |  1 +
 2 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/core/sis-cql/src/main/java/org/apache/sis/cql/FilterToCQLVisitor.java b/core/sis-cql/src/main/java/org/apache/sis/cql/FilterToCQLVisitor.java
index 3ffabcc..19ba6d4 100644
--- a/core/sis-cql/src/main/java/org/apache/sis/cql/FilterToCQLVisitor.java
+++ b/core/sis-cql/src/main/java/org/apache/sis/cql/FilterToCQLVisitor.java
@@ -21,6 +21,8 @@ import java.util.Date;
 import java.util.List;
 import java.util.regex.Pattern;
 import org.apache.sis.internal.util.StandardDateFormat;
+
+import org.locationtech.jts.geom.Envelope;
 import org.locationtech.jts.geom.Geometry;
 import org.locationtech.jts.io.WKTWriter;
 import org.opengis.filter.And;
@@ -287,27 +289,49 @@ final class FilterToCQLVisitor implements FilterVisitor, ExpressionVisitor
{
     public Object visit(final BBOX filter, final Object o) {
         final StringBuilder sb = toStringBuilder(o);
 
-        if (filter.getExpression1() instanceof PropertyName
-                && filter.getExpression2() instanceof Literal) {
+        final Expression left = filter.getExpression1();
+        final Expression right = filter.getExpression2();
+
+        final PropertyName pName = left instanceof PropertyName ? (PropertyName) left :
+                right instanceof PropertyName ? (PropertyName) right : null;
+        final Literal lit = left instanceof Literal ? (Literal) left :
+                right instanceof Literal ? (Literal) right : null;
+        final Envelope jtsEnv = lit.getValue() instanceof Envelope ? (Envelope) lit.getValue()
: null;
+        org.opengis.geometry.Envelope gisEnv = lit.getValue() instanceof org.opengis.geometry.Envelope
?
+                (org.opengis.geometry.Envelope) lit.getValue() : null;
+        if (pName != null && gisEnv != null || jtsEnv != null) {
             //use writing : BBOX(att,v1,v2,v3,v4)
             sb.append("BBOX(");
-            sb.append(filter.getPropertyName());
+            sb.append(pName.getPropertyName());
             sb.append(',');
-            sb.append(filter.getMinX());
+            final double minX, minY, maxX, maxY;
+            if (gisEnv != null) {
+                if (gisEnv.getDimension() > 2) throw new UnsupportedOperationException("Only
2D envelopes accepted");
+                minX = gisEnv.getMinimum(0);
+                maxX = gisEnv.getMaximum(0);
+                minY = gisEnv.getMinimum(1);
+                maxY = gisEnv.getMaximum(1);
+            } else {
+                minX = jtsEnv.getMinX();
+                maxX = jtsEnv.getMaxX();
+                minY = jtsEnv.getMinY();
+                maxY = jtsEnv.getMaxY();
+            }
+            sb.append(minX);
             sb.append(',');
-            sb.append(filter.getMaxX());
+            sb.append(maxX);
             sb.append(',');
-            sb.append(filter.getMinY());
+            sb.append(minY);
             sb.append(',');
-            sb.append(filter.getMaxY());
+            sb.append(maxY);
             sb.append(')');
 
         } else {
             //use writing BBOX(exp1,exp2)
             sb.append("BBOX(");
-            filter.getExpression1().accept(this, sb);
+            left.accept(this, sb);
             sb.append(',');
-            filter.getExpression2().accept(this, sb);
+            right.accept(this, sb);
             sb.append(')');
         }
 
diff --git a/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultBBOX.java b/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultBBOX.java
index 85ff6b2..338e801 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultBBOX.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultBBOX.java
@@ -229,6 +229,7 @@ final class DefaultBBOX extends SpatialFunction implements BBOX, Serializable
{
     public int hashCode() {
         return Objects.hash(left, right);
     }
+
     /*
      * DEPRECATED OPERATIONS: NOT IMPLEMENTED
      */


Mime
View raw message