Search in sources :

Example 6 with BinarySpatialOperator

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

the class OGC110Test method testFilterSpatialDisjoint.

// //////////////////////////////////////////////////////////////////////////
// JAXB TEST MARSHELLING AND UNMARSHELLING FOR SPATIAL FILTERS /////////////
// //////////////////////////////////////////////////////////////////////////
@Test
public void testFilterSpatialDisjoint() throws JAXBException, NoSuchAuthorityCodeException, FactoryException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_SPA_DISJOINT);
    assertNotNull(obj);
    JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
    assertNotNull(jaxfilter);
    Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
    assertNotNull(filter);
    BinarySpatialOperator prop = (BinarySpatialOperator) filter;
    BinarySpatialOperator subfilter = (BinarySpatialOperator) prop;
    ValueReference left = (ValueReference) subfilter.getOperand1();
    Literal right = (Literal) subfilter.getOperand2();
    assertEquals(left.getXPath(), valueStr);
    assertTrue(right.apply(null) instanceof Polygon);
    assertEquals(right.apply(null).toString().trim(), "POLYGON ((48 18, 48 21, 52 21, 52 18, 48 18))");
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) FilterType(org.geotoolkit.ogc.xml.v110.FilterType) Filter(org.opengis.filter.Filter) Literal(org.opengis.filter.Literal) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) Polygon(org.locationtech.jts.geom.Polygon) BinarySpatialOperator(org.opengis.filter.BinarySpatialOperator) ValueReference(org.opengis.filter.ValueReference) Test(org.junit.Test)

Example 7 with BinarySpatialOperator

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

the class OGCforSLD110Test method testCustom1.

@Test
public void testCustom1() throws JAXBException, FactoryException {
    StyleXmlIO util = new StyleXmlIO();
    final Filter filter = util.readFilter(OGCforSLD110Test.class.getResource("/org/geotoolkit/test/filter/filterbbox.xml"), org.geotoolkit.sld.xml.Specification.Filter.V_1_1_0);
    assertEquals(LogicalOperatorName.OR, filter.getOperatorType());
    final LogicalOperator<Object> or = (LogicalOperator) filter;
    final Filter f1 = or.getOperands().get(0);
    final Filter f2 = or.getOperands().get(1);
    assertEquals(ComparisonOperatorName.PROPERTY_IS_EQUAL_TO, f1.getOperatorType());
    assertEquals(SpatialOperatorName.BBOX, f2.getOperatorType());
    final BinaryComparisonOperator<Object> ff1 = (BinaryComparisonOperator) f1;
    final BinarySpatialOperator<Object> ff2 = (BinarySpatialOperator) f2;
    assertTrue(ff1.getOperand1() instanceof ValueReference);
    assertTrue(ff1.getOperand2() instanceof Literal);
    assertTrue(ff2.getOperand1() instanceof ValueReference);
    assertTrue(ff2.getOperand2() instanceof Literal);
    assertEquals("sf:str4Property", ((ValueReference) ff1.getOperand1()).getXPath());
    assertEquals("abc3", ((Literal) ff1.getOperand2()).getValue());
    assertEquals("sf:attribut.Géométrie", ((ValueReference) ff2.getOperand1()).getXPath());
    final Envelope2D geom = new Envelope2D((Envelope) ((Literal) ff2.getOperand2()).getValue());
    assertEquals(34d, geom.getMinX(), 1e-7);
    assertEquals(40d, geom.getMaxX(), 1e-7);
    assertEquals(15d, geom.getMinY(), 1e-7);
    assertEquals(19d, geom.getMaxY(), 1e-7);
    final CoordinateReferenceSystem crs = geom.getCoordinateReferenceSystem();
    assertEquals(CommonCRS.WGS84.geographic(), crs);
}
Also used : LogicalOperator(org.opengis.filter.LogicalOperator) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) Envelope2D(org.apache.sis.geometry.Envelope2D) Filter(org.opengis.filter.Filter) Literal(org.opengis.filter.Literal) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator) BinarySpatialOperator(org.opengis.filter.BinarySpatialOperator) ValueReference(org.opengis.filter.ValueReference) Test(org.junit.Test)

Aggregations

BinarySpatialOperator (org.opengis.filter.BinarySpatialOperator)7 Literal (org.opengis.filter.Literal)6 Filter (org.opengis.filter.Filter)5 ValueReference (org.opengis.filter.ValueReference)5 JAXBElement (javax.xml.bind.JAXBElement)4 Test (org.junit.Test)4 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Quantity (javax.measure.Quantity)2 Marshaller (javax.xml.bind.Marshaller)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 BinaryComparisonOperator (org.opengis.filter.BinaryComparisonOperator)2 Expression (org.opengis.filter.Expression)2 LogicalOperator (org.opengis.filter.LogicalOperator)2 FactoryException (org.opengis.util.FactoryException)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Document (org.apache.lucene.document.Document)1 LeafReader (org.apache.lucene.index.LeafReader)1