Search in sources :

Example 36 with BinaryComparisonOpType

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

the class OGC110Test method testFilterComparisonPropertyIsEqualTo.

@Test
public void testFilterComparisonPropertyIsEqualTo() throws JAXBException, NoSuchAuthorityCodeException, FactoryException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_COMP_ISEQUAL);
    assertNotNull(obj);
    JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
    assertNotNull(jaxfilter);
    Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
    assertNotNull(filter);
    BinaryComparisonOperator prop = (BinaryComparisonOperator) filter;
    ValueReference left = (ValueReference) prop.getOperand1();
    Literal right = (Literal) prop.getOperand2();
    assertEquals(left.getXPath(), valueStr);
    assertEquals(((Number) right.apply(null)).floatValue(), valueF, DELTA);
    // write test
    FilterType ft = TRANSFORMER_OGC.apply(filter);
    assertNotNull(ft.getComparisonOps());
    ComparisonOpsType cot = ft.getComparisonOps().getValue();
    BinaryComparisonOpType pibt = (BinaryComparisonOpType) cot;
    PropertyNameType lf = (PropertyNameType) pibt.getExpression().get(0).getValue();
    LiteralType rg = (LiteralType) pibt.getExpression().get(1).getValue();
    assertEquals(valueStr, lf.getContent());
    numberEquals(valueF, rg.getContent().get(0));
    MARSHALLER.marshal(ft.getComparisonOps(), TEST_FILE_FIL_COMP_ISEQUAL);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) ComparisonOpsType(org.geotoolkit.ogc.xml.v110.ComparisonOpsType) LiteralType(org.geotoolkit.ogc.xml.v110.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) FilterType(org.geotoolkit.ogc.xml.v110.FilterType) 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.v110.BinaryComparisonOpType) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) Test(org.junit.Test)

Example 37 with BinaryComparisonOpType

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

the class OGC110Test method testFilterComparisonPropertyIsNotEqualTo.

@Test
public void testFilterComparisonPropertyIsNotEqualTo() throws JAXBException, NoSuchAuthorityCodeException, FactoryException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_COMP_ISNOTEQUAL);
    assertNotNull(obj);
    JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
    assertNotNull(jaxfilter);
    Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
    assertNotNull(filter);
    BinaryComparisonOperator prop = (BinaryComparisonOperator) filter;
    ValueReference left = (ValueReference) prop.getOperand1();
    Literal right = (Literal) prop.getOperand2();
    assertEquals(left.getXPath(), valueStr);
    assertEquals(((Number) right.apply(null)).floatValue(), valueF, DELTA);
    // write test
    FilterType ft = TRANSFORMER_OGC.apply(filter);
    assertNotNull(ft.getComparisonOps());
    ComparisonOpsType cot = ft.getComparisonOps().getValue();
    BinaryComparisonOpType pibt = (BinaryComparisonOpType) cot;
    PropertyNameType lf = (PropertyNameType) pibt.getExpression().get(0).getValue();
    LiteralType rg = (LiteralType) pibt.getExpression().get(1).getValue();
    assertEquals(valueStr, lf.getContent());
    numberEquals(valueF, rg.getContent().get(0));
    MARSHALLER.marshal(ft.getComparisonOps(), TEST_FILE_FIL_COMP_ISNOTEQUAL);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) ComparisonOpsType(org.geotoolkit.ogc.xml.v110.ComparisonOpsType) LiteralType(org.geotoolkit.ogc.xml.v110.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) FilterType(org.geotoolkit.ogc.xml.v110.FilterType) 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.v110.BinaryComparisonOpType) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) Test(org.junit.Test)

Example 38 with BinaryComparisonOpType

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

the class OGC110toGTTransformer method visitComparisonOp.

/**
 * Transform a SLD comparison Filter v1.1 in GT filter.
 */
public Filter visitComparisonOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v110.ComparisonOpsType> jax) {
    final org.geotoolkit.ogc.xml.v110.ComparisonOpsType ops = jax.getValue();
    final String OpName = jax.getName().getLocalPart();
    if (ops instanceof org.geotoolkit.ogc.xml.v110.BinaryComparisonOpType) {
        final org.geotoolkit.ogc.xml.v110.BinaryComparisonOpType binary = (org.geotoolkit.ogc.xml.v110.BinaryComparisonOpType) ops;
        final Expression left = visitExpression(binary.getExpression().get(0));
        final Expression right = visitExpression(binary.getExpression().get(1));
        Boolean match = binary.getMatchCase();
        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.v110.PropertyIsLikeType) {
        final org.geotoolkit.ogc.xml.v110.PropertyIsLikeType property = (org.geotoolkit.ogc.xml.v110.PropertyIsLikeType) ops;
        final Expression expr = visitPropertyName(property.getPropertyName());
        final String pattern = (String) visitExpression(property.getLiteralType()).getValue();
        final char wild = property.getWildCard();
        final char single = property.getSingleChar();
        final char escape = property.getEscapeChar();
        if (OGCJAXBStatics.FILTER_COMPARISON_ISLIKE.equalsIgnoreCase(OpName)) {
            return filterFactory.like(expr, pattern, wild, single, escape, true);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v110.PropertyIsBetweenType) {
        final org.geotoolkit.ogc.xml.v110.PropertyIsBetweenType property = (org.geotoolkit.ogc.xml.v110.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.v110.PropertyIsNullType) {
        final org.geotoolkit.ogc.xml.v110.PropertyIsNullType property = (org.geotoolkit.ogc.xml.v110.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);
    }
    throw new IllegalArgumentException("Unknowed filter element" + jax);
}
Also used : MatchAction(org.opengis.filter.MatchAction) ComparisonOpsType(org.geotoolkit.ogc.xml.v110.ComparisonOpsType) Expression(org.opengis.filter.Expression)

Aggregations

Test (org.junit.Test)22 JAXBElement (javax.xml.bind.JAXBElement)21 Marshaller (javax.xml.bind.Marshaller)18 Unmarshaller (javax.xml.bind.Unmarshaller)18 BinaryComparisonOperator (org.opengis.filter.BinaryComparisonOperator)18 Filter (org.opengis.filter.Filter)18 Literal (org.opengis.filter.Literal)18 ValueReference (org.opengis.filter.ValueReference)18 BinaryComparisonOpType (net.opengis.filter.v_1_1_0.BinaryComparisonOpType)13 BinaryComparisonOpType (org.geotoolkit.ogc.xml.v100.BinaryComparisonOpType)9 FilterType (org.geotoolkit.ogc.xml.v100.FilterType)9 LiteralType (org.geotoolkit.ogc.xml.v100.LiteralType)9 PropertyNameType (org.geotoolkit.ogc.xml.v100.PropertyNameType)9 BinaryComparisonOpType (org.geotoolkit.ogc.xml.v110.BinaryComparisonOpType)9 FilterType (org.geotoolkit.ogc.xml.v110.FilterType)9 LiteralType (org.geotoolkit.ogc.xml.v110.LiteralType)9 PropertyNameType (org.geotoolkit.ogc.xml.v110.PropertyNameType)9 ComparisonOpsType (org.geotoolkit.ogc.xml.v110.ComparisonOpsType)7 ComparisonOpsType (org.geotoolkit.ogc.xml.v100.ComparisonOpsType)6 LogicalOperator (org.opengis.filter.LogicalOperator)6