Search in sources :

Example 16 with Literal

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

the class OGC100Test method testExpAdd.

// //////////////////////////////////////////////////////////////////////////
// JAXB TEST MARSHELLING AND UNMARSHELLING FOR EXPRESSION //////////////////
// //////////////////////////////////////////////////////////////////////////
@Test
public void testExpAdd() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_EXP_ADD);
    assertNotNull(obj);
    JAXBElement<BinaryOperatorType> jax = (JAXBElement<BinaryOperatorType>) obj;
    Expression exp = (Expression) TRANSFORMER_GT.visitExpression(jax);
    assertNotNull(exp);
    ValueReference left = (ValueReference) exp.getParameters().get(0);
    Literal right = (Literal) exp.getParameters().get(1);
    assertNotNull(left);
    assertNotNull(right);
    assertEquals(left.getXPath(), valueStr);
    assertEquals(((Number) right.apply(null)).floatValue(), valueF, DELTA);
    // Write test
    jax = (JAXBElement<BinaryOperatorType>) TRANSFORMER_OGC.extract(exp);
    assertNotNull(jax);
    assertEquals(jax.getName().getLocalPart(), OGCJAXBStatics.EXPRESSION_ADD);
    JAXBElement<PropertyNameType> ele1 = (JAXBElement<PropertyNameType>) jax.getValue().getExpression().get(0);
    JAXBElement<LiteralType> ele2 = (JAXBElement<LiteralType>) jax.getValue().getExpression().get(1);
    MARSHALLER.marshal(jax, TEST_FILE_EXP_ADD);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) BinaryOperatorType(org.geotoolkit.ogc.xml.v100.BinaryOperatorType) LiteralType(org.geotoolkit.ogc.xml.v100.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) Expression(org.opengis.filter.Expression) Literal(org.opengis.filter.Literal) Unmarshaller(javax.xml.bind.Unmarshaller) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) Test(org.junit.Test)

Example 17 with Literal

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

the class OGC100Test method testFilterComparisonPropertyIsBetween.

// //////////////////////////////////////////////////////////////////////////
// JAXB TEST MARSHELLING AND UNMARSHELLING FOR COMPARISON FILTERS //////////
// //////////////////////////////////////////////////////////////////////////
@Test
public void testFilterComparisonPropertyIsBetween() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_COMP_ISBETWEEN);
    assertNotNull(obj);
    JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
    assertNotNull(jaxfilter);
    Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
    assertNotNull(filter);
    BetweenComparisonOperator prop = (BetweenComparisonOperator) filter;
    ValueReference center = (ValueReference) prop.getExpression();
    Literal lower = (Literal) prop.getLowerBoundary();
    Literal upper = (Literal) prop.getUpperBoundary();
    assertEquals(center.getXPath(), valueStr);
    assertEquals(((Number) lower.apply(null)).floatValue(), 455f, DELTA);
    assertEquals(((Number) upper.apply(null)).floatValue(), 457f, DELTA);
    // write test
    FilterType ft = TRANSFORMER_OGC.apply(filter);
    assertNotNull(ft.getComparisonOps());
    ComparisonOpsType cot = ft.getComparisonOps().getValue();
    PropertyIsBetweenType pibt = (PropertyIsBetweenType) cot;
    PropertyNameType pnt = (PropertyNameType) pibt.getExpression().getValue();
    LiteralType low = (LiteralType) pibt.getLowerBoundary().getExpression().getValue();
    LiteralType up = (LiteralType) pibt.getUpperBoundary().getExpression().getValue();
    assertEquals(pnt.getContent(), valueStr);
    numberEquals(455, low.getContent().get(0));
    numberEquals(457, up.getContent().get(0));
    MARSHALLER.marshal(ft.getComparisonOps(), TEST_FILE_FIL_COMP_ISBETWEEN);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) ComparisonOpsType(org.geotoolkit.ogc.xml.v100.ComparisonOpsType) LiteralType(org.geotoolkit.ogc.xml.v100.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) FilterType(org.geotoolkit.ogc.xml.v100.FilterType) Filter(org.opengis.filter.Filter) Literal(org.opengis.filter.Literal) PropertyIsBetweenType(org.geotoolkit.ogc.xml.v100.PropertyIsBetweenType) Unmarshaller(javax.xml.bind.Unmarshaller) BetweenComparisonOperator(org.opengis.filter.BetweenComparisonOperator) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) Test(org.junit.Test)

Example 18 with Literal

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

the class OGC100Test method testFilterComparisonPropertyIsLessThan.

@Test
public void testFilterComparisonPropertyIsLessThan() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_COMP_ISLESS);
    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).toString().trim());
    MARSHALLER.marshal(ft.getComparisonOps(), TEST_FILE_FIL_COMP_ISLESS);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) ComparisonOpsType(org.geotoolkit.ogc.xml.v100.ComparisonOpsType) LiteralType(org.geotoolkit.ogc.xml.v100.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) FilterType(org.geotoolkit.ogc.xml.v100.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.v100.BinaryComparisonOpType) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) Test(org.junit.Test)

Example 19 with Literal

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

the class OGC100Test method testExpMul.

@Test
public void testExpMul() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_EXP_MUL);
    assertNotNull(obj);
    JAXBElement<BinaryOperatorType> jax = (JAXBElement<BinaryOperatorType>) obj;
    Expression exp = (Expression) TRANSFORMER_GT.visitExpression(jax);
    assertNotNull(exp);
    ValueReference left = (ValueReference) exp.getParameters().get(0);
    Literal right = (Literal) exp.getParameters().get(1);
    assertNotNull(left);
    assertNotNull(right);
    assertEquals(left.getXPath(), valueStr);
    assertEquals(((Number) right.apply(null)).floatValue(), valueF, DELTA);
    // Write test
    jax = (JAXBElement<BinaryOperatorType>) TRANSFORMER_OGC.extract(exp);
    assertNotNull(jax);
    assertEquals(jax.getName().getLocalPart(), OGCJAXBStatics.EXPRESSION_MUL);
    JAXBElement<PropertyNameType> ele1 = (JAXBElement<PropertyNameType>) jax.getValue().getExpression().get(0);
    JAXBElement<LiteralType> ele2 = (JAXBElement<LiteralType>) jax.getValue().getExpression().get(1);
    MARSHALLER.marshal(jax, TEST_FILE_EXP_MUL);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) BinaryOperatorType(org.geotoolkit.ogc.xml.v100.BinaryOperatorType) LiteralType(org.geotoolkit.ogc.xml.v100.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) Expression(org.opengis.filter.Expression) Literal(org.opengis.filter.Literal) Unmarshaller(javax.xml.bind.Unmarshaller) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) Test(org.junit.Test)

Example 20 with Literal

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

the class OGC100Test method testExpSub.

@Test
public void testExpSub() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_EXP_SUB);
    assertNotNull(obj);
    JAXBElement<BinaryOperatorType> jax = (JAXBElement<BinaryOperatorType>) obj;
    Expression exp = (Expression) TRANSFORMER_GT.visitExpression(jax);
    assertNotNull(exp);
    ValueReference left = (ValueReference) exp.getParameters().get(0);
    Literal right = (Literal) exp.getParameters().get(1);
    assertNotNull(left);
    assertNotNull(right);
    assertEquals(left.getXPath(), valueStr);
    assertEquals(((Number) right.apply(null)).floatValue(), valueF, DELTA);
    // Write test
    JAXBElement<BinaryOperatorType> pvt = (JAXBElement<BinaryOperatorType>) TRANSFORMER_OGC.extract(exp);
    assertNotNull(jax);
    assertEquals(jax.getName().getLocalPart(), OGCJAXBStatics.EXPRESSION_SUB);
    JAXBElement<PropertyNameType> ele1 = (JAXBElement<PropertyNameType>) jax.getValue().getExpression().get(0);
    JAXBElement<LiteralType> ele2 = (JAXBElement<LiteralType>) jax.getValue().getExpression().get(1);
    MARSHALLER.marshal(jax, TEST_FILE_EXP_SUB);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) BinaryOperatorType(org.geotoolkit.ogc.xml.v100.BinaryOperatorType) LiteralType(org.geotoolkit.ogc.xml.v100.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) Expression(org.opengis.filter.Expression) Literal(org.opengis.filter.Literal) Unmarshaller(javax.xml.bind.Unmarshaller) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) Test(org.junit.Test)

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