Search in sources :

Example 1 with Literal

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

the class CategoryStyleBuilder method analyze.

public void analyze(final MapLayer layer) {
    Resource resource = layer.getData();
    if (!(resource instanceof FeatureSet)) {
        throw new IllegalArgumentException("Layer resource must be a FeatureSet");
    }
    this.layer = layer;
    fts.rules().clear();
    properties.clear();
    if (layer != null) {
        FeatureType schema;
        try {
            schema = ((FeatureSet) resource).getType();
        } catch (DataStoreException ex) {
            throw new FeatureStoreRuntimeException(ex.getMessage(), ex);
        }
        for (PropertyType desc : schema.getProperties(true)) {
            if (desc instanceof AttributeType) {
                Class<?> type = ((AttributeType) desc).getValueClass();
                if (!Geometry.class.isAssignableFrom(type)) {
                    properties.add(ff.property(desc.getName().tip().toString()));
                }
            }
        }
        // find the geometry class for template
        Class<?> geoClass = null;
        try {
            PropertyType geo = FeatureExt.getDefaultGeometry(schema);
            geoClass = Features.toAttribute(geo).map(AttributeType::getValueClass).orElse(null);
        } catch (PropertyNotFoundException ex) {
            LOGGER.log(Level.FINE, "No sis:geometry property found", ex);
        }
        if (geoClass == null) {
            return;
        }
        if (Polygon.class.isAssignableFrom(geoClass) || MultiPolygon.class.isAssignableFrom(geoClass)) {
            Stroke stroke = sf.stroke(Color.BLACK, 1);
            Fill fill = sf.fill(Color.BLUE);
            template = sf.polygonSymbolizer(stroke, fill, null);
            expectedType = PolygonSymbolizer.class;
        } else if (LineString.class.isAssignableFrom(geoClass) || MultiLineString.class.isAssignableFrom(geoClass)) {
            Stroke stroke = sf.stroke(Color.BLUE, 2);
            template = sf.lineSymbolizer(stroke, null);
            expectedType = LineSymbolizer.class;
        } else {
            Stroke stroke = sf.stroke(Color.BLACK, 1);
            Fill fill = sf.fill(Color.BLUE);
            List<GraphicalSymbol> symbols = new ArrayList<>();
            symbols.add(sf.mark(StyleConstants.MARK_CIRCLE, fill, stroke));
            Graphic gra = sf.graphic(symbols, ff.literal(1), ff.literal(12), ff.literal(0), sf.anchorPoint(), sf.displacement());
            template = sf.pointSymbolizer(gra, null);
            expectedType = PointSymbolizer.class;
        }
        // try to rebuild the previous analyze if it was one
        List<? extends FeatureTypeStyle> ftss = layer.getStyle().featureTypeStyles();
        if (ftss.size() == 1) {
            FeatureTypeStyle fts = ftss.get(0);
            // defensive copy avoid synchronization
            List<? extends Rule> candidateRules = new ArrayList<>(fts.rules());
            for (Rule r : candidateRules) {
                // defensive copy avoid synchronization
                List<? extends Symbolizer> candidateSymbols = new ArrayList<>(r.symbolizers());
                if (candidateSymbols.size() != 1)
                    break;
                Symbolizer symbol = candidateSymbols.get(0);
                if (expectedType.isInstance(symbol)) {
                    if (r.isElseFilter()) {
                        // it looks like it's a valid classification "other" rule
                        this.fts.rules().add((MutableRule) r);
                        template = symbol;
                        other = true;
                    } else {
                        Filter f = r.getFilter();
                        if (f != null && f.getOperatorType() == ComparisonOperatorName.PROPERTY_IS_EQUAL_TO) {
                            BinaryComparisonOperator equal = (BinaryComparisonOperator) f;
                            Expression exp1 = equal.getOperand1();
                            Expression exp2 = equal.getOperand2();
                            if (exp1 instanceof ValueReference && exp2 instanceof Literal) {
                                if (properties.contains(exp1)) {
                                    // it looks like it's a valid classification property rule
                                    this.fts.rules().add((MutableRule) r);
                                    template = symbol;
                                    currentProperty = (ValueReference) exp1;
                                } else {
                                    // property is not in the schema
                                    break;
                                }
                            } else if (exp2 instanceof ValueReference && exp1 instanceof Literal) {
                                if (properties.contains(exp2)) {
                                    // it looks like it's a valid classification property rule
                                    this.fts.rules().add((MutableRule) r);
                                    template = symbol;
                                    currentProperty = (ValueReference) exp2;
                                } else {
                                    // property is not in the schema
                                    break;
                                }
                            } else {
                                // mismatch analyze structure
                                break;
                            }
                        }
                    }
                } else {
                    break;
                }
            }
        }
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) Fill(org.opengis.style.Fill) PropertyNotFoundException(org.opengis.feature.PropertyNotFoundException) ArrayList(java.util.ArrayList) PropertyType(org.opengis.feature.PropertyType) AttributeType(org.opengis.feature.AttributeType) Literal(org.opengis.filter.Literal) List(java.util.List) ArrayList(java.util.ArrayList) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) ValueReference(org.opengis.filter.ValueReference) PointSymbolizer(org.opengis.style.PointSymbolizer) DataStoreException(org.apache.sis.storage.DataStoreException) Stroke(org.opengis.style.Stroke) Graphic(org.opengis.style.Graphic) Resource(org.apache.sis.storage.Resource) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) Symbolizer(org.opengis.style.Symbolizer) Geometry(org.locationtech.jts.geom.Geometry) MutableRule(org.geotoolkit.style.MutableRule) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Filter(org.opengis.filter.Filter) Expression(org.opengis.filter.Expression) LineSymbolizer(org.opengis.style.LineSymbolizer) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) FeatureSet(org.apache.sis.storage.FeatureSet) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) FeatureTypeStyle(org.opengis.style.FeatureTypeStyle) Rule(org.opengis.style.Rule) MutableRule(org.geotoolkit.style.MutableRule) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator)

Example 2 with Literal

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

the class IntervalStyleBuilder method isIntervalStyle.

public boolean isIntervalStyle(final FeatureTypeStyle fts) {
    if (fts.rules().isEmpty())
        return false;
    for (Rule r : fts.rules()) {
        Filter f = r.getFilter();
        if (f == null || r.isElseFilter())
            return false;
        if (r.symbolizers().size() != 1)
            return false;
        if (f.getOperatorType() == LogicalOperatorName.AND) {
            LogicalOperator<Object> and = (LogicalOperator) f;
            if (and.getOperands().size() != 2)
                return false;
            Filter<Object> op1 = and.getOperands().get(0);
            Filter<Object> op2 = and.getOperands().get(1);
            if (op2.getOperatorType() == ComparisonOperatorName.PROPERTY_IS_GREATER_THAN_OR_EQUAL_TO) {
                // flip order
                op1 = op2;
                op2 = and.getOperands().get(0);
            }
            if (op1.getOperatorType() == ComparisonOperatorName.PROPERTY_IS_GREATER_THAN_OR_EQUAL_TO) {
                BinaryComparisonOperator under = (BinaryComparisonOperator) op1;
                Expression exp1 = under.getOperand1();
                Expression exp2 = under.getOperand2();
                if (exp1.getFunctionName().tip().toString().equals("Divide")) {
                    List parameters = exp1.getParameters();
                    if (!properties.contains(parameters.get(0)))
                        return false;
                    if (!properties.contains(parameters.get(1)))
                        return false;
                } else if (exp1 instanceof ValueReference) {
                    ValueReference name = (ValueReference) exp1;
                    if (!properties.contains(name))
                        return false;
                } else {
                    return false;
                }
                if (!(exp2 instanceof Literal)) {
                    return false;
                }
                if (op2.getOperatorType() == ComparisonOperatorName.PROPERTY_IS_LESS_THAN || op2.getOperatorType() == ComparisonOperatorName.PROPERTY_IS_LESS_THAN_OR_EQUAL_TO) {
                    BinaryComparisonOperator bc = (BinaryComparisonOperator) op2;
                    Expression ex1 = under.getOperand1();
                    Expression ex2 = under.getOperand2();
                    if (exp1.getFunctionName().tip().toString().equals("Divide")) {
                        List parameters = exp1.getParameters();
                        if (!properties.contains(parameters.get(0)))
                            return false;
                        if (!properties.contains(parameters.get(1)))
                            return false;
                    } else if (exp1 instanceof ValueReference) {
                        ValueReference name = (ValueReference) ex1;
                        if (!properties.contains(name))
                            return false;
                    } else {
                        return false;
                    }
                    if (!(ex2 instanceof Literal)) {
                        return false;
                    }
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
        template = r.symbolizers().get(0);
    }
    method = METHOD.MANUAL;
    nbClasses = fts.rules().size() + 1;
    return true;
}
Also used : Filter(org.opengis.filter.Filter) Expression(org.opengis.filter.Expression) LogicalOperator(org.opengis.filter.LogicalOperator) Literal(org.opengis.filter.Literal) List(java.util.List) ArrayList(java.util.ArrayList) Rule(org.opengis.style.Rule) MutableRule(org.geotoolkit.style.MutableRule) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator) ValueReference(org.opengis.filter.ValueReference)

Example 3 with Literal

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

the class FilterFactory2 method intersects.

public BinarySpatialOperator<Object> intersects(final String propertyName, final Geometry geometry) {
    final ValueReference name = property(propertyName);
    final Literal geom = super.literal(geometry);
    return intersects(name, geom);
}
Also used : Literal(org.opengis.filter.Literal) ValueReference(org.opengis.filter.ValueReference)

Example 4 with Literal

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

the class FilterFactory2 method within.

public BinarySpatialOperator<Object> within(final String propertyName, final Geometry geometry) {
    final ValueReference name = property(propertyName);
    final Literal geom = super.literal(geometry);
    return within(name, geom);
}
Also used : Literal(org.opengis.filter.Literal) ValueReference(org.opengis.filter.ValueReference)

Example 5 with Literal

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

the class FilterFactory2 method disjoint.

public BinarySpatialOperator<Object> disjoint(final String propertyName, final Geometry geometry) {
    final ValueReference name = property(propertyName);
    final Literal geom = super.literal(geometry);
    return disjoint(name, geom);
}
Also used : Literal(org.opengis.filter.Literal) ValueReference(org.opengis.filter.ValueReference)

Aggregations

Literal (org.opengis.filter.Literal)108 Test (org.junit.Test)74 Expression (org.opengis.filter.Expression)64 ValueReference (org.opengis.filter.ValueReference)52 JAXBElement (javax.xml.bind.JAXBElement)37 Filter (org.opengis.filter.Filter)37 Marshaller (javax.xml.bind.Marshaller)33 Unmarshaller (javax.xml.bind.Unmarshaller)33 LineString (org.locationtech.jts.geom.LineString)27 MultiLineString (org.locationtech.jts.geom.MultiLineString)27 BinaryComparisonOperator (org.opengis.filter.BinaryComparisonOperator)25 Geometry (org.locationtech.jts.geom.Geometry)20 LiteralType (org.geotoolkit.ogc.xml.v110.LiteralType)17 LiteralType (org.geotoolkit.ogc.xml.v100.LiteralType)16 PropertyNameType (org.geotoolkit.ogc.xml.v100.PropertyNameType)15 PropertyNameType (org.geotoolkit.ogc.xml.v110.PropertyNameType)15 ArrayList (java.util.ArrayList)12 FilterType (org.geotoolkit.ogc.xml.v110.FilterType)12 LogicalOperator (org.opengis.filter.LogicalOperator)11 FilterType (org.geotoolkit.ogc.xml.v100.FilterType)10