Search in sources :

Example 36 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class CapabilitiesFilterSplitter method visitBinaryComparisonOperator.

private void visitBinaryComparisonOperator(final BinaryComparisonOperator<Object> filter) {
    if (original == null) {
        original = filter;
    }
    // supports it as a group -- no need to check the type
    if (!fcs.supports(filter)) {
        postStack.addFirst(filter);
        return;
    }
    final int i = postStack.size();
    final Expression leftValue = filter.getOperand1();
    final Expression rightValue = filter.getOperand2();
    if (leftValue == null || rightValue == null) {
        postStack.addFirst(filter);
        return;
    }
    visit(leftValue, null);
    if (i < postStack.size()) {
        postStack.removeFirst();
        postStack.addFirst(filter);
        return;
    }
    visit(rightValue, null);
    if (i < postStack.size()) {
        // left
        preStack.removeFirst();
        postStack.removeFirst();
        postStack.addFirst(filter);
        return;
    }
    // left side
    preStack.removeFirst();
    // right side
    preStack.removeFirst();
    preStack.addFirst(filter);
}
Also used : Expression(org.opengis.filter.Expression)

Example 37 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class LuceneOGCWeight method scorer.

@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
    // final SortedDocValues values = context.reader().getSortedDocValues(IDENTIFIER_FIELD_NAME);
    final LeafReader reader = context.reader();
    boolean treeSearch = false;
    boolean reverse = false;
    boolean distanceFilter = false;
    final Set<String> treeMatching = new HashSet<>();
    if (tree != null) {
        /*
             * For distance buffer filter no envelope only mode
             */
        List<Expression<Object, ?>> expressions = filter.getExpressions();
        Expression e2 = (expressions.size() >= 2) ? expressions.get(1) : null;
        if (filter instanceof DistanceOperator) {
            distanceFilter = true;
            reverse = filter.getOperatorType() == DistanceOperatorName.BEYOND;
            final DistanceOperator sp = (DistanceOperator) filter;
            if (e2 instanceof Literal) {
                try {
                    final Literal lit = (Literal) e2;
                    Quantity distance = sp.getDistance();
                    final GeneralEnvelope bound = getExtendedReprojectedEnvelope(lit.getValue(), tree.getCrs(), distance.getUnit().toString(), distance.getValue().doubleValue());
                    final int[] resultID = tree.searchID(bound);
                    Arrays.sort(resultID);
                    treeMatching.clear();
                    TreeElementMapper<NamedEnvelope> tem = tree.getTreeElementMapper();
                    for (int id : resultID) {
                        final NamedEnvelope env = tem.getObjectFromTreeIdentifier(id);
                        if (env != null) {
                            treeMatching.add(env.getId());
                        }
                    }
                    treeSearch = true;
                } catch (FactoryException ex) {
                    throw new IOException(ex);
                } catch (StoreIndexException ex) {
                    Throwable cause = ex.getCause();
                    if (cause instanceof IOException) {
                        throw (IOException) cause;
                    } else {
                        throw new IOException(ex);
                    }
                }
            } else {
                LOGGER.log(Level.WARNING, "Not a literal for spatial filter:{0}", e2);
            }
        } else if (filter instanceof BinarySpatialOperator) {
            final BinarySpatialOperator sp = (BinarySpatialOperator) filter;
            if (e2 instanceof Literal) {
                final Literal lit = (Literal) e2;
                final Envelope boundFilter = getReprojectedEnvelope(lit.getValue(), tree.getCrs());
                try {
                    if (filterType == SpatialFilterType.CROSSES || !envelopeOnly) {
                        if (filterType == SpatialFilterType.DISJOINT) {
                            reverse = true;
                        }
                        final int[] resultID = tree.searchID(boundFilter);
                        Arrays.sort(resultID);
                        final TreeElementMapper<NamedEnvelope> tem = tree.getTreeElementMapper();
                        treeMatching.clear();
                        for (int id : resultID) {
                            final NamedEnvelope env = tem.getObjectFromTreeIdentifier(id);
                            if (env != null) {
                                treeMatching.add(env.getId());
                            }
                        }
                        treeSearch = true;
                        envelopeOnly = false;
                    } else {
                        final int[] resultID = TreeX.search(tree, boundFilter, filterType);
                        Arrays.sort(resultID);
                        final TreeElementMapper<NamedEnvelope> tem = tree.getTreeElementMapper();
                        treeMatching.clear();
                        for (int id : resultID) {
                            final NamedEnvelope env = tem.getObjectFromTreeIdentifier(id);
                            if (env != null) {
                                treeMatching.add(env.getId());
                            }
                        }
                        treeSearch = true;
                    }
                } catch (StoreIndexException ex) {
                    Throwable cause = ex.getCause();
                    if (cause instanceof IOException) {
                        throw (IOException) cause;
                    } else {
                        throw new IOException(ex);
                    }
                }
            } else {
                LOGGER.log(Level.WARNING, "Not a literal for spatial filter:{0}", e2);
            }
        } else {
            LOGGER.log(Level.WARNING, "not a spatial operator:{0}", filter.getClass().getName());
        }
    } else {
        LOGGER.finer("Null R-tree in spatial search");
    }
    final BitSet set = new FixedBitSet(reader.maxDoc());
    Bits b = reader.getLiveDocs();
    if (b == null) {
        b = new Bits.MatchAllBits(reader.maxDoc());
    }
    for (int i = 0; i < b.length(); i++) {
        if (b.get(i)) {
            final int docId = i;
            final Document doc = reader.document(docId, ID_FIELDS);
            final String id = doc.get(IDENTIFIER_FIELD_NAME);
            final boolean match = treeMatching.contains(id);
            if (treeSearch && reverse && !match) {
                set.set(docId);
            } else if (!treeSearch || match) {
                if (envelopeOnly && !distanceFilter) {
                    set.set(docId);
                } else {
                    final Document geoDoc = reader.document(docId, GEOMETRY_FIELDS);
                    if (filter.test(geoDoc)) {
                        set.set(docId);
                    }
                }
            }
        }
    }
    return new ConstantScoreScorer(this, boost, scoreMode, new BitSetIterator(set, 5));
}
Also used : NamedEnvelope(org.geotoolkit.index.tree.manager.NamedEnvelope) FactoryException(org.opengis.util.FactoryException) Envelope(org.opengis.geometry.Envelope) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) LuceneUtils.getReprojectedEnvelope(org.geotoolkit.lucene.LuceneUtils.getReprojectedEnvelope) LuceneUtils.getExtendedReprojectedEnvelope(org.geotoolkit.lucene.LuceneUtils.getExtendedReprojectedEnvelope) NamedEnvelope(org.geotoolkit.index.tree.manager.NamedEnvelope) Document(org.apache.lucene.document.Document) ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) FixedBitSet(org.apache.lucene.util.FixedBitSet) Literal(org.opengis.filter.Literal) HashSet(java.util.HashSet) BinarySpatialOperator(org.opengis.filter.BinarySpatialOperator) StoreIndexException(org.geotoolkit.index.tree.StoreIndexException) BitSetIterator(org.apache.lucene.util.BitSetIterator) LeafReader(org.apache.lucene.index.LeafReader) DistanceOperator(org.opengis.filter.DistanceOperator) FixedBitSet(org.apache.lucene.util.FixedBitSet) BitSet(org.apache.lucene.util.BitSet) Quantity(javax.measure.Quantity) IOException(java.io.IOException) Expression(org.opengis.filter.Expression) TreeElementMapper(org.geotoolkit.index.tree.TreeElementMapper) Bits(org.apache.lucene.util.Bits) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope)

Example 38 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class DefaultStyleVisitor method visit.

@Override
public Object visit(final AnchorPoint anchorPoint, Object data) {
    final Expression x = anchorPoint.getAnchorPointX();
    if (x != null) {
        visit(x, data);
    }
    final Expression y = anchorPoint.getAnchorPointY();
    if (y != null) {
        visit(y, data);
    }
    return data;
}
Also used : Expression(org.opengis.filter.Expression)

Example 39 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class DefaultStyleVisitor method visit.

@Override
public Object visit(final Stroke stroke, Object data) {
    final Expression color = stroke.getColor();
    if (color != null) {
        visit(color, data);
    }
    final Expression offset = stroke.getDashOffset();
    if (offset != null) {
        visit(offset, data);
    }
    final GraphicFill gf = stroke.getGraphicFill();
    if (gf != null) {
        data = visit(gf, data);
    }
    final GraphicStroke gs = stroke.getGraphicStroke();
    if (gs != null) {
        data = visit(gs, data);
    }
    final Expression lc = stroke.getLineCap();
    if (lc != null) {
        visit(lc, data);
    }
    final Expression lj = stroke.getLineJoin();
    if (lj != null) {
        visit(lj, data);
    }
    final Expression opa = stroke.getOpacity();
    if (opa != null) {
        visit(opa, data);
    }
    final Expression width = stroke.getWidth();
    if (width != null) {
        visit(width, data);
    }
    return data;
}
Also used : Expression(org.opengis.filter.Expression) GraphicFill(org.opengis.style.GraphicFill) GraphicStroke(org.opengis.style.GraphicStroke)

Example 40 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class DefaultStyleVisitor method visit.

@Override
public Object visit(final Font font, Object data) {
    final List<Expression> families = font.getFamily();
    if (families != null) {
        for (Expression family : families) {
            visit(family, data);
        }
    }
    final Expression size = font.getSize();
    if (size != null) {
        visit(size, data);
    }
    final Expression style = font.getStyle();
    if (style != null) {
        visit(style, data);
    }
    final Expression weight = font.getWeight();
    if (weight != null) {
        visit(weight, data);
    }
    return data;
}
Also used : Expression(org.opengis.filter.Expression)

Aggregations

Expression (org.opengis.filter.Expression)325 Test (org.junit.Test)112 LineString (org.locationtech.jts.geom.LineString)73 Literal (org.opengis.filter.Literal)65 ArrayList (java.util.ArrayList)47 MultiLineString (org.locationtech.jts.geom.MultiLineString)46 Unit (javax.measure.Unit)45 Description (org.opengis.style.Description)40 Fill (org.opengis.style.Fill)38 GraphicFill (org.opengis.style.GraphicFill)38 Stroke (org.opengis.style.Stroke)35 Geometry (org.locationtech.jts.geom.Geometry)31 Displacement (org.opengis.style.Displacement)29 GraphicStroke (org.opengis.style.GraphicStroke)29 ValueReference (org.opengis.filter.ValueReference)27 JAXBElement (javax.xml.bind.JAXBElement)22 LineSymbolizer (org.opengis.style.LineSymbolizer)22 PointSymbolizer (org.opengis.style.PointSymbolizer)22 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)22 MutableStyle (org.geotoolkit.style.MutableStyle)21