Search in sources :

Example 11 with DistanceBufferType

use of net.opengis.filter.v_2_0_0.DistanceBufferType in project ddf by codice.

the class TestWfsFilterDelegate method testLogicalAndOfSpatialTemporal.

/**
     * Verifies that a temporal criteria can be AND'ed to other criteria.
     *
     * @throws Exception
     */
@Test
public void testLogicalAndOfSpatialTemporal() throws Exception {
    String mockProperty = "myPropertyName";
    String mockType = "myType";
    WfsFilterDelegate delegate = mockFeatureMetacardCreateDelegate(mockProperty, mockType);
    FilterType spatialFilter = delegate.dwithin(Metacard.ANY_GEO, "POINT (30 10)", Double.valueOf(1000));
    FilterType temporalFilter = delegate.during(mockProperty, new DateTime().minusDays(365).toDate(), new DateTime().minusDays(10).toDate());
    List<FilterType> filtersToBeAnded = new ArrayList<>(Arrays.asList(spatialFilter, temporalFilter));
    //Perform Test
    FilterType filter = delegate.and(filtersToBeAnded);
    //Verify AND op used
    if (filter.getLogicOps() == null) {
        fail("No AND/OR element found in the generated FilterType.");
    }
    assertEquals(LOGICAL_AND_NAME, filter.getLogicOps().getName().toString());
    BinaryLogicOpType logicOpType = (BinaryLogicOpType) filter.getLogicOps().getValue();
    //Verify two items were AND'ed
    assertEquals(2, logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().size());
    //Verify first is spatial, second is temporal
    assertTrue(logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(0).getValue() instanceof DistanceBufferType);
    assertTrue(logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(1).getValue() instanceof BinaryTemporalOpType);
}
Also used : FilterType(net.opengis.filter.v_2_0_0.FilterType) BinaryLogicOpType(net.opengis.filter.v_2_0_0.BinaryLogicOpType) ArrayList(java.util.ArrayList) DistanceBufferType(net.opengis.filter.v_2_0_0.DistanceBufferType) DateTime(org.joda.time.DateTime) BinaryTemporalOpType(net.opengis.filter.v_2_0_0.BinaryTemporalOpType) Test(org.junit.Test)

Example 12 with DistanceBufferType

use of net.opengis.filter.v_2_0_0.DistanceBufferType in project ddf by codice.

the class TestWfsFilterDelegate method testDwithinAsNotBeyond.

@Test
public void testDwithinAsNotBeyond() {
    WfsFilterDelegate delegate = setupFilterDelegate(SPATIAL_OPERATORS.Beyond.toString());
    FilterType filter = delegate.dwithin(Metacard.ANY_GEO, POLYGON, DISTANCE);
    assertTrue(filter.getLogicOps().getValue() instanceof UnaryLogicOpType);
    UnaryLogicOpType type = (UnaryLogicOpType) filter.getLogicOps().getValue();
    assertTrue(type.getSpatialOps().getValue() instanceof DistanceBufferType);
}
Also used : UnaryLogicOpType(net.opengis.filter.v_2_0_0.UnaryLogicOpType) FilterType(net.opengis.filter.v_2_0_0.FilterType) DistanceBufferType(net.opengis.filter.v_2_0_0.DistanceBufferType) Test(org.junit.Test)

Example 13 with DistanceBufferType

use of net.opengis.filter.v_2_0_0.DistanceBufferType in project ddf by codice.

the class TestWfsFilterDelegate method testDWithinFilterPoint.

@Test
public void testDWithinFilterPoint() throws SAXException, IOException, JAXBException {
    WfsFilterDelegate delegate = setupFilterDelegate(SPATIAL_OPERATORS.DWithin.toString());
    FilterType filter = delegate.dwithin(Metacard.ANY_GEO, POINT, DISTANCE);
    assertFalse(filter.isSetLogicOps());
    assertTrue(filter.isSetSpatialOps());
    assertTrue(filter.getSpatialOps().getValue() instanceof DistanceBufferType);
    assertXMLEqual(MockWfsServer.getDWithinPointXmlFilter(), getXmlFromMarshaller(filter));
}
Also used : FilterType(net.opengis.filter.v_2_0_0.FilterType) DistanceBufferType(net.opengis.filter.v_2_0_0.DistanceBufferType) Test(org.junit.Test)

Example 14 with DistanceBufferType

use of net.opengis.filter.v_2_0_0.DistanceBufferType in project ddf by codice.

the class WfsFilterDelegate method buildDistanceBufferType.

private JAXBElement<DistanceBufferType> buildDistanceBufferType(JAXBElement<DistanceBufferType> dbt, String propertyName, String wkt, double distance) {
    MeasureType measureType = new MeasureType();
    measureType.setValue(distance);
    // the filter adapter normalizes all distances to meters
    measureType.setUom(Wfs20Constants.METERS);
    dbt.getValue().setDistance(measureType);
    dbt.getValue().setExpression(filterObjectFactory.createValueReference(propertyName));
    dbt.getValue().setAny(createGeometryOperand(wkt));
    return dbt;
}
Also used : MeasureType(net.opengis.filter.v_2_0_0.MeasureType)

Example 15 with DistanceBufferType

use of net.opengis.filter.v_2_0_0.DistanceBufferType in project ddf by codice.

the class TestWfsFilterDelegate method testLogicalAndOrSpatial.

private void testLogicalAndOrSpatial(String methName, String compOpName) throws Exception {
    String mockProperty = "myPropertyName";
    String mockType = "myType";
    WfsFilterDelegate delegate = mockFeatureMetacardCreateDelegate(mockProperty, mockType);
    FilterType spatialFilter1 = delegate.dwithin(Metacard.ANY_GEO, "POINT (30 10)", Double.valueOf(1000));
    FilterType spatialFilter2 = delegate.dwithin(Metacard.ANY_GEO, "POINT (50 10)", Double.valueOf(1500));
    List<FilterType> filtersToCombine = new ArrayList<>();
    filtersToCombine.add(spatialFilter1);
    filtersToCombine.add(spatialFilter2);
    //Perform Test
    Method method = WfsFilterDelegate.class.getMethod(methName, List.class);
    FilterType filter = (FilterType) method.invoke(delegate, filtersToCombine);
    //Verify
    assertThat(filter.getLogicOps().getName().toString(), is(compOpName));
    BinaryLogicOpType logicOpType = (BinaryLogicOpType) filter.getLogicOps().getValue();
    DistanceBufferType spatialOpsType1 = (DistanceBufferType) logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(0).getValue();
    assertThat(Double.toString(spatialOpsType1.getDistance().getValue()), is(Double.valueOf(1000).toString()));
    DistanceBufferType spatialOpsType2 = (DistanceBufferType) logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(1).getValue();
    assertThat(Double.toString(spatialOpsType2.getDistance().getValue()), is(Double.valueOf(1500).toString()));
}
Also used : FilterType(net.opengis.filter.v_2_0_0.FilterType) BinaryLogicOpType(net.opengis.filter.v_2_0_0.BinaryLogicOpType) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) DistanceBufferType(net.opengis.filter.v_2_0_0.DistanceBufferType)

Aggregations

DistanceBufferType (net.opengis.filter.v_2_0_0.DistanceBufferType)9 FilterType (net.opengis.filter.v_2_0_0.FilterType)9 Test (org.junit.Test)9 DistanceBufferType (net.opengis.filter.v_1_1_0.DistanceBufferType)6 ArrayList (java.util.ArrayList)3 DistanceType (net.opengis.filter.v_1_1_0.DistanceType)3 PropertyNameType (net.opengis.filter.v_1_1_0.PropertyNameType)3 BinaryLogicOpType (net.opengis.filter.v_2_0_0.BinaryLogicOpType)3 UnaryLogicOpType (net.opengis.filter.v_2_0_0.UnaryLogicOpType)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 Method (java.lang.reflect.Method)2 BinaryTemporalOpType (net.opengis.filter.v_2_0_0.BinaryTemporalOpType)1 MeasureType (net.opengis.filter.v_2_0_0.MeasureType)1 PropertyIsLikeType (net.opengis.filter.v_2_0_0.PropertyIsLikeType)1 AbstractGeometryType (net.opengis.gml.v_3_1_1.AbstractGeometryType)1 DateTime (org.joda.time.DateTime)1