sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ama...@apache.org
Subject [sis] 29/45: WIP(Feature): start BBOX implementation
Date Tue, 12 Nov 2019 16:44:56 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 4901855003432aaf3b9fbd669b8798110699f7f8
Author: Alexis Manin <amanin@apache.org>
AuthorDate: Tue Oct 8 17:55:31 2019 +0200

    WIP(Feature): start BBOX implementation
---
 .../java/org/apache/sis/filter/DefaultBBOX.java    | 105 +++++++++++++++++++++
 1 file changed, 105 insertions(+)

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
new file mode 100644
index 0000000..8f233ba
--- /dev/null
+++ b/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultBBOX.java
@@ -0,0 +1,105 @@
+package org.apache.sis.filter;
+
+import org.opengis.filter.FilterVisitor;
+import org.opengis.filter.expression.Expression;
+import org.opengis.filter.spatial.BBOX;
+import org.opengis.geometry.Envelope;
+import org.opengis.metadata.extent.GeographicBoundingBox;
+
+import org.apache.sis.geometry.GeneralEnvelope;
+import org.apache.sis.internal.feature.Geometries;
+
+import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+
+/**
+ * @implNote AMBIGUITY : Description of BBOX operator from <a href="http://docs.opengeospatial.org/is/09-026r2/09-026r2.html#60">
+ *     filter encoding 2.0.2</a> is rather succinct, and do not well explain if both
tested expressions must be
+ *     envelopes, or if we should test an envelope against a real geometry. What we will
do in this implementation is
+ *     testing bbox only, because the test for a bbox against a complex geometry can be realized
using ST_Intersect
+ *     operator.
+ *
+ *     TODO: optimisations in case one of the two operators is a literal.
+ *     TODO: CRS check.
+ */
+final class DefaultBBOX implements BBOX {
+
+    final Expression left;
+    final Expression right;
+
+    public DefaultBBOX(Expression left, Expression right) {
+        ensureNonNull("Left expression", left);
+        ensureNonNull("Right expression", right);
+        this.left = left;
+        this.right = right;
+    }
+
+    @Override
+    public Expression getExpression1() {
+        return left;
+    }
+
+    @Override
+    public Expression getExpression2() {
+        return right;
+    }
+
+    @Override
+    public boolean evaluate(Object object) {
+        Envelope leftEval = asEnvelope(left, object);
+        Envelope rightEval = asEnvelope(right, object);
+        // If both are null, return a match.
+        if (leftEval == rightEval) return true;
+        return GeneralEnvelope.castOrCopy(leftEval).intersects(rightEval);
+    }
+
+    private static Envelope asEnvelope(final Expression evaluator, final Object data) {
+        Envelope eval = evaluator.evaluate(data, Envelope.class);
+        if (eval == null) {
+            final Object tmpVal = evaluator.evaluate(data);
+            if (tmpVal instanceof Envelope) {
+                eval = (Envelope) tmpVal;
+            } else if (tmpVal instanceof GeographicBoundingBox) {
+                eval = new GeneralEnvelope((GeographicBoundingBox) tmpVal);
+            } else {
+                eval = Geometries.getEnvelope(tmpVal);
+            }
+        }
+
+        return eval;
+    }
+
+    @Override
+    public Object accept(FilterVisitor visitor, Object extraData) {
+        return visitor.visit(this, extraData);
+    }
+
+    @Override
+    public String getPropertyName() {
+        throw new UnsupportedOperationException("Not supported yet"); // "Alexis Manin (Geomatys)"
on 08/10/2019
+    }
+
+    @Override
+    public String getSRS() {
+        throw new UnsupportedOperationException("Not supported yet"); // "Alexis Manin (Geomatys)"
on 08/10/2019
+    }
+
+    @Override
+    public double getMinX() {
+        throw new UnsupportedOperationException("Not supported yet"); // "Alexis Manin (Geomatys)"
on 08/10/2019
+    }
+
+    @Override
+    public double getMinY() {
+        throw new UnsupportedOperationException("Not supported yet"); // "Alexis Manin (Geomatys)"
on 08/10/2019
+    }
+
+    @Override
+    public double getMaxX() {
+        throw new UnsupportedOperationException("Not supported yet"); // "Alexis Manin (Geomatys)"
on 08/10/2019
+    }
+
+    @Override
+    public double getMaxY() {
+        throw new UnsupportedOperationException("Not supported yet"); // "Alexis Manin (Geomatys)"
on 08/10/2019
+    }
+}


Mime
View raw message