Search in sources :

Example 11 with ComparisonOpsType

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

the class OGC110Test method testFilterComparisonPropertyIsGreaterThan.

@Test
public void testFilterComparisonPropertyIsGreaterThan() throws JAXBException, NoSuchAuthorityCodeException, FactoryException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_COMP_ISGREATER);
    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_ISGREATER);
    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 12 with ComparisonOpsType

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

the class OGC110Test method testFilterComparisonPropertyIsGreaterThanOrEqual.

@Test
public void testFilterComparisonPropertyIsGreaterThanOrEqual() throws JAXBException, NoSuchAuthorityCodeException, FactoryException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_COMP_ISGREATEROREQUAL);
    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_ISGREATEROREQUAL);
    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 13 with ComparisonOpsType

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

the class OGC110Test method testFilterComparisonPropertyIsNull.

@Test
public void testFilterComparisonPropertyIsNull() throws JAXBException, NoSuchAuthorityCodeException, FactoryException {
    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.v110.FilterType) PropertyIsNullType(org.geotoolkit.ogc.xml.v110.PropertyIsNullType) Filter(org.opengis.filter.Filter) ComparisonOpsType(org.geotoolkit.ogc.xml.v110.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.v110.PropertyNameType) Test(org.junit.Test)

Example 14 with ComparisonOpsType

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

the class FilterToOGC100Converter method apply.

@Override
public FilterType apply(final Filter filter) {
    if (filter == null) {
        return null;
    }
    JAXBElement<?> sf = visit(filter);
    if (sf == null) {
        return null;
    }
    final FilterType ft = ogc_factory.createFilterType();
    if (sf.getValue() instanceof ComparisonOpsType) {
        ft.setComparisonOps((JAXBElement<? extends ComparisonOpsType>) sf);
    } else if (sf.getValue() instanceof LogicOpsType) {
        ft.setLogicOps((JAXBElement<? extends LogicOpsType>) sf);
    } else if (sf.getValue() instanceof SpatialOpsType) {
        ft.setSpatialOps((JAXBElement<? extends SpatialOpsType>) sf);
    } else {
        // should not happen
        throw new IllegalArgumentException("invalide filter element : " + sf);
    }
    return ft;
}
Also used : FilterType(org.geotoolkit.ogc.xml.v100.FilterType) SpatialOpsType(org.geotoolkit.ogc.xml.v100.SpatialOpsType) ComparisonOpsType(org.geotoolkit.ogc.xml.v100.ComparisonOpsType) JAXBElement(javax.xml.bind.JAXBElement) LogicOpsType(org.geotoolkit.ogc.xml.v100.LogicOpsType)

Example 15 with ComparisonOpsType

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

the class OGC110toGTTransformer method visitLogicOp.

/**
 * Transform a SLD logic Filter v1.1 in GT filter.
 */
public Filter visitLogicOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v110.LogicOpsType> jax) throws NoSuchAuthorityCodeException, FactoryException {
    final org.geotoolkit.ogc.xml.v110.LogicOpsType ops = jax.getValue();
    final String OpName = jax.getName().getLocalPart();
    if (ops instanceof org.geotoolkit.ogc.xml.v110.UnaryLogicOpType) {
        final org.geotoolkit.ogc.xml.v110.UnaryLogicOpType unary = (org.geotoolkit.ogc.xml.v110.UnaryLogicOpType) ops;
        if (OGCJAXBStatics.FILTER_LOGIC_NOT.equalsIgnoreCase(OpName)) {
            Filter filter = null;
            if (unary.getComparisonOps() != null) {
                filter = visitComparisonOp(unary.getComparisonOps());
            } else if (unary.getLogicOps() != null) {
                filter = visitLogicOp(unary.getLogicOps());
            } else if (unary.getSpatialOps() != null) {
                filter = visitSpatialOp(unary.getSpatialOps());
            }
            if (filter == null) {
                throw new IllegalArgumentException("Invalide filter element" + unary);
            }
            return filterFactory.not(filter);
        }
    } else if (ops instanceof org.geotoolkit.ogc.xml.v110.BinaryLogicOpType) {
        final org.geotoolkit.ogc.xml.v110.BinaryLogicOpType binary = (org.geotoolkit.ogc.xml.v110.BinaryLogicOpType) ops;
        if (OGCJAXBStatics.FILTER_LOGIC_AND.equalsIgnoreCase(OpName)) {
            final List<Filter> filters = new ArrayList<Filter>();
            for (final JAXBElement<? extends ComparisonOpsType> ele : binary.getComparisonOps()) {
                if (ele.getValue() instanceof ComparisonOpsType) {
                    filters.add(visitComparisonOp(ele));
                }
            }
            for (final JAXBElement<? extends LogicOpsType> ele : binary.getLogicOps()) {
                if (ele.getValue() instanceof LogicOpsType) {
                    filters.add(visitLogicOp(ele));
                }
            }
            for (final JAXBElement<? extends SpatialOpsType> ele : binary.getSpatialOps()) {
                if (ele.getValue() instanceof SpatialOpsType) {
                    filters.add(visitSpatialOp(ele));
                }
            }
            if (filters.isEmpty()) {
                return Filter.include();
            } else if (filters.size() == 1) {
                return filters.get(0);
            } else {
                return filterFactory.and((List) filters);
            }
        } else if (OGCJAXBStatics.FILTER_LOGIC_OR.equalsIgnoreCase(OpName)) {
            final List<Filter> filters = new ArrayList<Filter>();
            for (final JAXBElement<? extends ComparisonOpsType> ele : binary.getComparisonOps()) {
                if (ele.getValue() instanceof ComparisonOpsType) {
                    filters.add(visitComparisonOp(ele));
                }
            }
            for (final JAXBElement<? extends LogicOpsType> ele : binary.getLogicOps()) {
                if (ele.getValue() instanceof LogicOpsType) {
                    filters.add(visitLogicOp(ele));
                }
            }
            for (final JAXBElement<? extends SpatialOpsType> ele : binary.getSpatialOps()) {
                if (ele.getValue() instanceof SpatialOpsType) {
                    filters.add(visitSpatialOp(ele));
                }
            }
            if (filters.isEmpty()) {
                return Filter.include();
            } else if (filters.size() == 1) {
                return filters.get(0);
            } else {
                return filterFactory.or((List) filters);
            }
        }
    }
    throw new IllegalArgumentException("Unknowed filter element" + jax);
}
Also used : ArrayList(java.util.ArrayList) LogicOpsType(org.geotoolkit.ogc.xml.v110.LogicOpsType) ComparisonOpsType(org.geotoolkit.ogc.xml.v110.ComparisonOpsType) JAXBElement(javax.xml.bind.JAXBElement) LogicOpsType(org.geotoolkit.ogc.xml.v110.LogicOpsType) Filter(org.opengis.filter.Filter) SpatialOpsType(org.geotoolkit.ogc.xml.v110.SpatialOpsType) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)23 Filter (org.opengis.filter.Filter)20 ValueReference (org.opengis.filter.ValueReference)19 Marshaller (javax.xml.bind.Marshaller)18 Unmarshaller (javax.xml.bind.Unmarshaller)18 Test (org.junit.Test)18 Literal (org.opengis.filter.Literal)15 BinaryComparisonOperator (org.opengis.filter.BinaryComparisonOperator)13 ComparisonOpsType (org.geotoolkit.ogc.xml.v100.ComparisonOpsType)11 ComparisonOpsType (org.geotoolkit.ogc.xml.v110.ComparisonOpsType)11 FilterType (org.geotoolkit.ogc.xml.v100.FilterType)10 PropertyNameType (org.geotoolkit.ogc.xml.v100.PropertyNameType)10 LiteralType (org.geotoolkit.ogc.xml.v100.LiteralType)9 FilterType (org.geotoolkit.ogc.xml.v110.FilterType)9 PropertyNameType (org.geotoolkit.ogc.xml.v110.PropertyNameType)9 LiteralType (org.geotoolkit.ogc.xml.v110.LiteralType)8 BinaryComparisonOpType (org.geotoolkit.ogc.xml.v100.BinaryComparisonOpType)6 BinaryComparisonOpType (org.geotoolkit.ogc.xml.v110.BinaryComparisonOpType)6 LikeOperator (org.opengis.filter.LikeOperator)3 NullOperator (org.opengis.filter.NullOperator)3