Search in sources :

Example 6 with PropertyIsNullType

use of org.geotoolkit.ogc.xml.v200.PropertyIsNullType in project geotoolkit by Geomatys.

the class OGC100Test method testFilterComparisonPropertyIsNull.

@Test
public void testFilterComparisonPropertyIsNull() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_COMP_ISNULL);
    assertNotNull(obj);
    JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
    assertNotNull(jaxfilter);
    Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
    assertNotNull(filter);
    NullOperator prop = (NullOperator) filter;
    ValueReference center = (ValueReference) prop.getExpressions().get(0);
    assertEquals(center.getXPath(), valueStr);
    // write test
    FilterType ft = TRANSFORMER_OGC.apply(filter);
    assertNotNull(ft.getComparisonOps());
    ComparisonOpsType cot = ft.getComparisonOps().getValue();
    PropertyIsNullType pibt = (PropertyIsNullType) cot;
    PropertyNameType pnt = (PropertyNameType) pibt.getPropertyName();
    assertEquals(pnt.getContent(), valueStr);
    MARSHALLER.marshal(ft.getComparisonOps(), TEST_FILE_FIL_COMP_ISNULL);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) FilterType(org.geotoolkit.ogc.xml.v100.FilterType) PropertyIsNullType(org.geotoolkit.ogc.xml.v100.PropertyIsNullType) Filter(org.opengis.filter.Filter) ComparisonOpsType(org.geotoolkit.ogc.xml.v100.ComparisonOpsType) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) NullOperator(org.opengis.filter.NullOperator) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) Test(org.junit.Test)

Example 7 with PropertyIsNullType

use of org.geotoolkit.ogc.xml.v200.PropertyIsNullType in project geotoolkit by Geomatys.

the class OGC200toGTTransformer method visitComparisonOp.

/**
 * Transform a SLD comparison Filter v1.1 in GT filter.
 */
public Filter visitComparisonOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v200.ComparisonOpsType> jax) {
    final org.geotoolkit.ogc.xml.v200.ComparisonOpsType ops = jax.getValue();
    final String OpName = jax.getName().getLocalPart();
    if (ops instanceof org.geotoolkit.ogc.xml.v200.BinaryComparisonOpType) {
        final org.geotoolkit.ogc.xml.v200.BinaryComparisonOpType binary = (org.geotoolkit.ogc.xml.v200.BinaryComparisonOpType) ops;
        if (binary.getExpression().size() < 2) {
            throw new IllegalArgumentException("comparison operator must have two expression (valueReference and literal)");
        }
        final Expression left = visitExpression(binary.getExpression().get(0));
        final Expression right = visitExpression(binary.getExpression().get(1));
        Boolean match = binary.isMatchingCase();
        if (match == null) {
            match = Boolean.TRUE;
        }
        final MatchAction action = binary.getMatchAction();
        if (OGCJAXBStatics.FILTER_COMPARISON_ISEQUAL.equalsIgnoreCase(OpName)) {
            return filterFactory.equal(left, right, match, action);
        } else if (OGCJAXBStatics.FILTER_COMPARISON_ISNOTEQUAL.equalsIgnoreCase(OpName)) {
            return filterFactory.notEqual(left, right, match, action);
        } else if (OGCJAXBStatics.FILTER_COMPARISON_ISLESS.equalsIgnoreCase(OpName)) {
            return filterFactory.less(left, right, match, action);
        } else if (OGCJAXBStatics.FILTER_COMPARISON_ISGREATER.equalsIgnoreCase(OpName)) {
            return filterFactory.greater(left, right, match, action);
        } else if (OGCJAXBStatics.FILTER_COMPARISON_ISLESSOREQUAL.equalsIgnoreCase(OpName)) {
            return filterFactory.lessOrEqual(left, right, match, action);
        } else if (OGCJAXBStatics.FILTER_COMPARISON_ISGREATEROREQUAL.equalsIgnoreCase(OpName)) {
            return filterFactory.greaterOrEqual(left, right, match, action);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v200.PropertyIsLikeType) {
        final org.geotoolkit.ogc.xml.v200.PropertyIsLikeType property = (org.geotoolkit.ogc.xml.v200.PropertyIsLikeType) ops;
        final Expression expr = visitPropertyName(property.getPropertyName());
        final String pattern = visitExpression(property.getLiteralType()).toString();
        final char wild = property.getWildCard();
        final char single = property.getSingleChar();
        final char escape = property.getEscapeChar();
        final boolean matchCase = property.isMatchingCase();
        if (OGCJAXBStatics.FILTER_COMPARISON_ISLIKE.equalsIgnoreCase(OpName)) {
            return filterFactory.like(expr, pattern, wild, single, escape, matchCase);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v200.PropertyIsBetweenType) {
        final org.geotoolkit.ogc.xml.v200.PropertyIsBetweenType property = (org.geotoolkit.ogc.xml.v200.PropertyIsBetweenType) ops;
        final Expression lower = visitExpression(property.getLowerBoundary().getExpression());
        final Expression upper = visitExpression(property.getUpperBoundary().getExpression());
        final Expression expr = visitExpression(property.getExpressionType());
        if (OGCJAXBStatics.FILTER_COMPARISON_ISBETWEEN.equalsIgnoreCase(OpName)) {
            return filterFactory.between(expr, lower, upper);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v200.PropertyIsNullType) {
        final org.geotoolkit.ogc.xml.v200.PropertyIsNullType property = (org.geotoolkit.ogc.xml.v200.PropertyIsNullType) ops;
        final Expression expr = visitPropertyName(property.getPropertyName());
        if (OGCJAXBStatics.FILTER_COMPARISON_ISNULL.equalsIgnoreCase(OpName)) {
            return filterFactory.isNull(expr);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v200.PropertyIsNilType) {
        final org.geotoolkit.ogc.xml.v200.PropertyIsNilType property = (org.geotoolkit.ogc.xml.v200.PropertyIsNilType) ops;
        final Expression expr = visitPropertyName(property.getPropertyName());
        if (OGCJAXBStatics.FILTER_COMPARISON_ISNIL.equalsIgnoreCase(OpName)) {
            return filterFactory.isNil(expr, null);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    }
    throw new IllegalArgumentException("Unknowed filter element" + jax);
}
Also used : org.geotoolkit.ogc.xml.v200(org.geotoolkit.ogc.xml.v200) MatchAction(org.opengis.filter.MatchAction) Expression(org.opengis.filter.Expression)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)5 Filter (org.opengis.filter.Filter)5 NullOperator (org.opengis.filter.NullOperator)5 ValueReference (org.opengis.filter.ValueReference)5 List (java.util.List)3 Expression (org.opengis.filter.Expression)3 ArrayList (java.util.ArrayList)2 Marshaller (javax.xml.bind.Marshaller)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 ComparisonOpsType (org.geotoolkit.ogc.xml.v100.ComparisonOpsType)2 PropertyIsNullType (org.geotoolkit.ogc.xml.v100.PropertyIsNullType)2 PropertyNameType (org.geotoolkit.ogc.xml.v100.PropertyNameType)2 PropertyIsNullType (org.geotoolkit.ogc.xml.v110.PropertyIsNullType)2 PropertyNameType (org.geotoolkit.ogc.xml.v110.PropertyNameType)2 BetweenComparisonOperator (org.opengis.filter.BetweenComparisonOperator)2 BinaryComparisonOperator (org.opengis.filter.BinaryComparisonOperator)2 LikeOperator (org.opengis.filter.LikeOperator)2 Literal (org.opengis.filter.Literal)2 LogicalOperator (org.opengis.filter.LogicalOperator)2 CodeList (org.opengis.util.CodeList)2