Search in sources :

Example 81 with PropertyNameType

use of org.geotoolkit.ogc.xml.v110.PropertyNameType in project geotoolkit by Geomatys.

the class FilterFactoryImpl method notEqual.

@Override
public BinaryComparisonOperator<Object> notEqual(final Expression<Object, ?> expr1, final Expression<Object, ?> expr2) {
    LiteralType lit = null;
    PropertyNameType propName = null;
    if (expr1 instanceof PropertyNameType) {
        propName = (PropertyNameType) expr1;
    } else if (expr2 instanceof PropertyNameType) {
        propName = (PropertyNameType) expr2;
    }
    if (expr1 instanceof LiteralType) {
        lit = (LiteralType) expr1;
    } else if (expr2 instanceof LiteralType) {
        lit = (LiteralType) expr2;
    }
    return new PropertyIsNotEqualToType(lit, propName, null);
}
Also used : PropertyIsNotEqualToType(org.geotoolkit.ogc.xml.v110.PropertyIsNotEqualToType) LiteralType(org.geotoolkit.ogc.xml.v110.LiteralType) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType)

Example 82 with PropertyNameType

use of org.geotoolkit.ogc.xml.v110.PropertyNameType in project geotoolkit by Geomatys.

the class FilterFactoryImpl method beyond.

@Override
public DistanceOperator<Object> beyond(final Expression geometry1, final Expression geometry2, final double distance, String units) {
    String propertyName = "";
    if (geometry1 instanceof PropertyNameType) {
        propertyName = ((PropertyNameType) geometry1).getXPath();
    } else {
        throw new IllegalArgumentException("unexpected type instead of propertyNameType: " + geometry1.getClass().getSimpleName());
    }
    // we transform the JTS geometry into a GML geometry
    Object geom = null;
    if (geometry2 instanceof LiteralType) {
        geom = ((LiteralType) geometry2).getValue();
        geom = GeometryToGML(geom);
    }
    // we formats the units (CQL parser add a white space at the end)
    if (units.indexOf(' ') == units.length() - 1) {
        units = units.substring(0, units.length() - 1);
    }
    return new BeyondType(propertyName, (AbstractGeometryType) geom, distance, units);
}
Also used : BeyondType(org.geotoolkit.ogc.xml.v110.BeyondType) LiteralType(org.geotoolkit.ogc.xml.v110.LiteralType) LineString(org.locationtech.jts.geom.LineString) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType)

Example 83 with PropertyNameType

use of org.geotoolkit.ogc.xml.v110.PropertyNameType in project geotoolkit by Geomatys.

the class FilterFactoryImpl method endedBy.

@Override
public TemporalOperator<Object> endedBy(final Expression<Object, ?> expr1, final Expression<Object, ?> expr2) {
    Object temporal = null;
    PropertyNameType propName = null;
    if (expr1 instanceof PropertyNameType) {
        propName = (PropertyNameType) expr1;
        temporal = expr2;
    } else if (expr2 instanceof PropertyNameType) {
        propName = (PropertyNameType) expr2;
        temporal = expr1;
    }
    return new TimeEndedByType(propName.getXPath(), temporal);
}
Also used : TimeEndedByType(org.geotoolkit.ogc.xml.v110.TimeEndedByType) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType)

Example 84 with PropertyNameType

use of org.geotoolkit.ogc.xml.v110.PropertyNameType in project geotoolkit by Geomatys.

the class FilterToOGC100Converter method visit.

@Override
public JAXBElement<?> visit(final Filter filter) {
    if (filter.equals(Filter.include())) {
        return null;
    }
    if (filter.equals(Filter.exclude())) {
        return null;
    }
    final CodeList<?> type = filter.getOperatorType();
    if (filter instanceof BetweenComparisonOperator) {
        final BetweenComparisonOperator pib = (BetweenComparisonOperator) filter;
        final PropertyIsBetweenType bot = ogc_factory.createPropertyIsBetweenType();
        final LowerBoundaryType lbt = ogc_factory.createLowerBoundaryType();
        lbt.setExpression(extract(pib.getLowerBoundary()));
        final UpperBoundaryType ubt = ogc_factory.createUpperBoundaryType();
        ubt.setExpression(extract(pib.getUpperBoundary()));
        bot.setExpression(extract(pib.getExpression()));
        bot.setLowerBoundary(lbt);
        bot.setUpperBoundary(ubt);
        return ogc_factory.createPropertyIsBetween(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsEqualToType bot = new PropertyIsEqualToType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsEqualTo(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_GREATER_THAN) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsGreaterThanType bot = new PropertyIsGreaterThanType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsGreaterThan(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_GREATER_THAN_OR_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsGreaterThanOrEqualToType bot = new PropertyIsGreaterThanOrEqualToType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsGreaterThanOrEqualTo(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_LESS_THAN) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsLessThanType bot = new PropertyIsLessThanType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsLessThan(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_LESS_THAN_OR_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsLessThanOrEqualToType bot = new PropertyIsLessThanOrEqualToType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsLessThanOrEqualTo(bot);
    } else if (filter instanceof LikeOperator) {
        final LikeOperator pis = (LikeOperator) filter;
        final List<Expression> expressions = filter.getExpressions();
        final PropertyIsLikeType bot = ogc_factory.createPropertyIsLikeType();
        bot.setEscape(String.valueOf(pis.getEscapeChar()));
        final LiteralType lt = ogc_factory.createLiteralType();
        lt.getContent().add(((Literal) expressions.get(1)).getValue());
        bot.setLiteral(lt);
        final Expression expression = expressions.get(0);
        if (!(expression instanceof ValueReference)) {
            throw new IllegalArgumentException("LikeOperator can support ValueReference only, but was a " + expression);
        }
        final PropertyNameType pnt = (PropertyNameType) extract(expression).getValue();
        bot.setPropertyName(pnt);
        bot.setSingleChar(String.valueOf(pis.getSingleChar()));
        bot.setWildCard(String.valueOf(pis.getWildCard()));
        return ogc_factory.createPropertyIsLike(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_NOT_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsNotEqualToType bot = new PropertyIsNotEqualToType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsNotEqualTo(bot);
    } else if (filter instanceof NullOperator) {
        final NullOperator pis = (NullOperator) filter;
        final PropertyIsNullType bot = ogc_factory.createPropertyIsNullType();
        final Object obj = extract((Expression) pis.getExpressions().get(0)).getValue();
        if (obj instanceof LiteralType) {
            bot.setLiteral((LiteralType) obj);
        } else if (obj instanceof PropertyNameType) {
            bot.setPropertyName((PropertyNameType) obj);
        } else {
            // should not be possible
            throw new IllegalArgumentException("Invalid expression element : " + obj);
        }
        return ogc_factory.createPropertyIsNull(bot);
    } else if (type == LogicalOperatorName.AND) {
        final LogicalOperator and = (LogicalOperator) filter;
        final AndType lot = new AndType();
        for (final Filter f : (List<Filter>) and.getOperands()) {
            lot.getComparisonOpsOrSpatialOpsOrLogicOps().add(visit(f));
        }
        return ogc_factory.createAnd(lot);
    } else if (type == LogicalOperatorName.OR) {
        final LogicalOperator or = (LogicalOperator) filter;
        final OrType lot = new OrType();
        for (final Filter f : (List<Filter>) or.getOperands()) {
            lot.getComparisonOpsOrSpatialOpsOrLogicOps().add(visit(f));
        }
        return ogc_factory.createOr(lot);
    } else if (type == LogicalOperatorName.NOT) {
        final LogicalOperator not = (LogicalOperator) filter;
        final NotType lot = new NotType();
        JAXBElement<?> sf = visit((Filter) not.getOperands().get(0));
        if (sf.getValue() instanceof ComparisonOpsType) {
            lot.setComparisonOps((JAXBElement<? extends ComparisonOpsType>) sf);
        } else if (sf.getValue() instanceof LogicOpsType) {
            lot.setLogicOps((JAXBElement<? extends LogicOpsType>) sf);
        } else if (sf.getValue() instanceof SpatialOpsType) {
            lot.setSpatialOps((JAXBElement<? extends SpatialOpsType>) sf);
        } else {
            // should not happen
            throw new IllegalArgumentException("invalid filter element : " + sf);
        }
        return ogc_factory.createNot(lot);
    } else if (type == SpatialOperatorName.BBOX) {
        final BBOX bbox = BBOX.wrap((BinarySpatialOperator) filter);
        final BBOXType bboxType = ogc_factory.createBBOXType();
        final Expression sourceExp1 = bbox.getOperand1();
        final JAXBElement<?> exp1 = extract(sourceExp1);
        final Expression sourceExp2 = bbox.getOperand2();
        JAXBElement<?> exp2 = extract(sourceExp2);
        final PropertyNameType pName;
        final BoxType boxType;
        if (exp1 != null && exp1.getValue() instanceof PropertyNameType) {
            pName = (PropertyNameType) exp1.getValue();
        } else if (exp2 != null && exp2.getValue() instanceof PropertyNameType) {
            pName = (PropertyNameType) exp2.getValue();
        } else
            throw new IllegalArgumentException("No property name found in given bbox filter");
        if (sourceExp1 instanceof Literal) {
            boxType = toBox((Literal) sourceExp1);
        } else if (sourceExp2 instanceof Literal) {
            boxType = toBox((Literal) sourceExp2);
        } else
            throw new IllegalArgumentException("No bbox found in given bbox filter");
        bboxType.setPropertyName(pName);
        bboxType.setBox(boxType);
        return ogc_factory.createBBOX(bboxType);
    }
    throw new IllegalArgumentException("Unknowed filter element : " + filter + " class :" + filter.getClass());
}
Also used : PropertyIsLessThanType(org.geotoolkit.ogc.xml.v100.PropertyIsLessThanType) AndType(org.geotoolkit.ogc.xml.v100.AndType) PropertyIsLessThanOrEqualToType(org.geotoolkit.ogc.xml.v100.PropertyIsLessThanOrEqualToType) BoxType(org.geotoolkit.gml.xml.v212.BoxType) PropertyIsNullType(org.geotoolkit.ogc.xml.v100.PropertyIsNullType) NotType(org.geotoolkit.ogc.xml.v100.NotType) SpatialOpsType(org.geotoolkit.ogc.xml.v100.SpatialOpsType) Literal(org.opengis.filter.Literal) CodeList(org.opengis.util.CodeList) List(java.util.List) PropertyIsBetweenType(org.geotoolkit.ogc.xml.v100.PropertyIsBetweenType) BetweenComparisonOperator(org.opengis.filter.BetweenComparisonOperator) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) OrType(org.geotoolkit.ogc.xml.v100.OrType) PropertyIsGreaterThanType(org.geotoolkit.ogc.xml.v100.PropertyIsGreaterThanType) LogicalOperator(org.opengis.filter.LogicalOperator) ComparisonOpsType(org.geotoolkit.ogc.xml.v100.ComparisonOpsType) LiteralType(org.geotoolkit.ogc.xml.v100.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) PropertyIsGreaterThanOrEqualToType(org.geotoolkit.ogc.xml.v100.PropertyIsGreaterThanOrEqualToType) NullOperator(org.opengis.filter.NullOperator) LogicOpsType(org.geotoolkit.ogc.xml.v100.LogicOpsType) UpperBoundaryType(org.geotoolkit.ogc.xml.v100.UpperBoundaryType) PropertyIsNotEqualToType(org.geotoolkit.ogc.xml.v100.PropertyIsNotEqualToType) PropertyIsEqualToType(org.geotoolkit.ogc.xml.v100.PropertyIsEqualToType) BBOXType(org.geotoolkit.ogc.xml.v100.BBOXType) Expression(org.opengis.filter.Expression) Filter(org.opengis.filter.Filter) LowerBoundaryType(org.geotoolkit.ogc.xml.v100.LowerBoundaryType) LikeOperator(org.opengis.filter.LikeOperator) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator) PropertyIsLikeType(org.geotoolkit.ogc.xml.v100.PropertyIsLikeType)

Example 85 with PropertyNameType

use of org.geotoolkit.ogc.xml.v110.PropertyNameType in project geotoolkit by Geomatys.

the class OGC100Test method testFilterLogicalOr.

@Test
public void testFilterLogicalOr() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_LOG_OR);
    assertNotNull(obj);
    JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
    assertNotNull(jaxfilter);
    Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
    assertNotNull(filter);
    LogicalOperator prop = (LogicalOperator) filter;
    BinaryComparisonOperator leftop = (BinaryComparisonOperator) prop.getOperands().get(0);
    BinaryComparisonOperator rightop = (BinaryComparisonOperator) prop.getOperands().get(1);
    ValueReference left = (ValueReference) leftop.getOperand1();
    Literal right = (Literal) leftop.getOperand2();
    assertEquals(left.getXPath(), valueStr);
    assertEquals(((Number) right.apply(null)).floatValue(), 455f, DELTA);
    left = (ValueReference) rightop.getOperand1();
    right = (Literal) rightop.getOperand2();
    assertEquals(left.getXPath(), valueStr);
    assertEquals(((Number) right.apply(null)).floatValue(), 457f, DELTA);
    // write test
    FilterType ft = TRANSFORMER_OGC.apply(filter);
    assertNotNull(ft.getLogicOps());
    LogicOpsType cot = ft.getLogicOps().getValue();
    assertEquals(ft.getLogicOps().getName().getLocalPart(), OGCJAXBStatics.FILTER_LOGIC_OR);
    BinaryLogicOpType pibt = (BinaryLogicOpType) cot;
    BinaryComparisonOpType leftoptype = (BinaryComparisonOpType) pibt.getComparisonOpsOrSpatialOpsOrLogicOps().get(0).getValue();
    BinaryComparisonOpType rightoptype = (BinaryComparisonOpType) pibt.getComparisonOpsOrSpatialOpsOrLogicOps().get(1).getValue();
    PropertyNameType lf = (PropertyNameType) leftoptype.getExpression().get(0).getValue();
    LiteralType rg = (LiteralType) leftoptype.getExpression().get(1).getValue();
    assertEquals(valueStr, lf.getContent());
    numberEquals(455, rg.getContent().get(0));
    lf = (PropertyNameType) rightoptype.getExpression().get(0).getValue();
    rg = (LiteralType) rightoptype.getExpression().get(1).getValue();
    assertEquals(valueStr, lf.getContent());
    numberEquals(457, rg.getContent().get(0));
    MARSHALLER.marshal(ft.getLogicOps(), TEST_FILE_FIL_LOG_OR);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) LogicalOperator(org.opengis.filter.LogicalOperator) LiteralType(org.geotoolkit.ogc.xml.v100.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) LogicOpsType(org.geotoolkit.ogc.xml.v100.LogicOpsType) FilterType(org.geotoolkit.ogc.xml.v100.FilterType) BinaryLogicOpType(org.geotoolkit.ogc.xml.v100.BinaryLogicOpType) Filter(org.opengis.filter.Filter) Literal(org.opengis.filter.Literal) Unmarshaller(javax.xml.bind.Unmarshaller) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator) BinaryComparisonOpType(org.geotoolkit.ogc.xml.v100.BinaryComparisonOpType) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) Test(org.junit.Test)

Aggregations

PropertyNameType (org.geotoolkit.ogc.xml.v110.PropertyNameType)62 JAXBElement (javax.xml.bind.JAXBElement)47 Test (org.junit.Test)39 Unmarshaller (javax.xml.bind.Unmarshaller)38 LiteralType (org.geotoolkit.ogc.xml.v110.LiteralType)38 Marshaller (javax.xml.bind.Marshaller)37 ValueReference (org.opengis.filter.ValueReference)37 Literal (org.opengis.filter.Literal)31 Filter (org.opengis.filter.Filter)27 PropertyNameType (org.geotoolkit.ogc.xml.v100.PropertyNameType)20 BinaryComparisonOperator (org.opengis.filter.BinaryComparisonOperator)20 FilterType (org.geotoolkit.ogc.xml.v110.FilterType)17 LiteralType (org.geotoolkit.ogc.xml.v100.LiteralType)16 PropertyNameType (net.opengis.filter.v_1_1_0.PropertyNameType)13 FilterType (org.geotoolkit.ogc.xml.v100.FilterType)12 Expression (org.opengis.filter.Expression)12 ComparisonOpsType (org.geotoolkit.ogc.xml.v100.ComparisonOpsType)10 BinaryComparisonOpType (org.geotoolkit.ogc.xml.v100.BinaryComparisonOpType)9 BinaryComparisonOpType (org.geotoolkit.ogc.xml.v110.BinaryComparisonOpType)9 ComparisonOpsType (org.geotoolkit.ogc.xml.v110.ComparisonOpsType)9