Search in sources :

Example 16 with BBOXType

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

the class FilterXMLBindingTest method filterUnmarshalingTest.

/**
 * Test simple Record Marshalling.
 *
 * @throws JAXBException
 */
@Test
public void filterUnmarshalingTest() throws JAXBException {
    /*
         * Test Unmarshalling spatial filter.
         */
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + "    <ogc:Overlaps>" + '\n' + "        <ogc:PropertyName>boundingBox</ogc:PropertyName>" + '\n' + "        <gml:Envelope srsName=\"EPSG:4326\">" + '\n' + "            <gml:lowerCorner>10.0 11.0</gml:lowerCorner>" + '\n' + "            <gml:upperCorner>10.0 11.0</gml:upperCorner>" + '\n' + "        </gml:Envelope>" + '\n' + "    </ogc:Overlaps>" + '\n' + "</ogc:Filter>" + '\n';
    StringReader sr = new StringReader(xml);
    JAXBElement jb = (JAXBElement) unmarshaller.unmarshal(sr);
    FilterType result = (FilterType) jb.getValue();
    DirectPositionType lowerCorner = new DirectPositionType(10.0, 11.0);
    DirectPositionType upperCorner = new DirectPositionType(10.0, 11.0);
    EnvelopeType envelope = new EnvelopeType(lowerCorner, upperCorner, "EPSG:4326");
    OverlapsType filterElement = new OverlapsType(new PropertyNameType("boundingBox"), envelope);
    FilterType expResult = new FilterType(filterElement);
    assertEquals(expResult.getSpatialOps().getValue(), result.getSpatialOps().getValue());
    assertEquals(expResult, result);
    xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/fes/2.0\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + "    <ogc:BBOX>" + '\n' + "        <ogc:ValueReference>boundingBox</ogc:ValueReference>" + '\n' + "        <gml:Envelope srsName=\"EPSG:4326\">" + '\n' + "            <gml:lowerCorner>10.0 11.0</gml:lowerCorner>" + '\n' + "            <gml:upperCorner>10.0 11.0</gml:upperCorner>" + '\n' + "        </gml:Envelope>" + '\n' + "    </ogc:BBOX>" + '\n' + "</ogc:Filter>" + '\n';
    sr = new StringReader(xml);
    jb = (JAXBElement) unmarshaller.unmarshal(sr);
    org.geotoolkit.ogc.xml.v200.FilterType result2 = (org.geotoolkit.ogc.xml.v200.FilterType) jb.getValue();
    final org.geotoolkit.gml.xml.v311.ObjectFactory gmlFactory = new org.geotoolkit.gml.xml.v311.ObjectFactory();
    BBOXType filterBox = new BBOXType("boundingBox", gmlFactory.createEnvelope(envelope));
    org.geotoolkit.ogc.xml.v200.FilterType expResult2 = new org.geotoolkit.ogc.xml.v200.FilterType(filterBox);
    assertEquals(((JAXBElement) ((BBOXType) expResult2.getSpatialOps().getValue()).getAny()).getValue(), ((JAXBElement) ((BBOXType) result2.getSpatialOps().getValue()).getAny()).getValue());
    assertEquals(expResult2.getSpatialOps().getValue(), result2.getSpatialOps().getValue());
    assertEquals(expResult2, result2);
    xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/fes/2.0\">" + '\n' + "    <ogc:BBOX>" + '\n' + "        <ogc:ValueReference>boundingBox</ogc:ValueReference>" + '\n' + "        $test" + '\n' + "    </ogc:BBOX>" + '\n' + "</ogc:Filter>" + '\n';
    sr = new StringReader(xml);
    jb = (JAXBElement) unmarshaller.unmarshal(sr);
    result2 = (org.geotoolkit.ogc.xml.v200.FilterType) jb.getValue();
    filterBox = new BBOXType("boundingBox", "$test");
    expResult2 = new org.geotoolkit.ogc.xml.v200.FilterType(filterBox);
    assertEquals(expResult2.getSpatialOps().getValue(), result2.getSpatialOps().getValue());
    assertEquals(expResult2, result2);
    xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/fes/2.0\">" + '\n' + "    <ogc:Contains>" + '\n' + "        <ogc:ValueReference>boundingBox</ogc:ValueReference>" + '\n' + "        $test" + '\n' + "    </ogc:Contains>" + '\n' + "</ogc:Filter>" + '\n';
    sr = new StringReader(xml);
    jb = (JAXBElement) unmarshaller.unmarshal(sr);
    result2 = (org.geotoolkit.ogc.xml.v200.FilterType) jb.getValue();
    ContainsType filterContains = new ContainsType("boundingBox", "$test");
    expResult2 = new org.geotoolkit.ogc.xml.v200.FilterType(filterContains);
    assertEquals(expResult2.getSpatialOps().getValue(), result2.getSpatialOps().getValue());
    assertEquals(expResult2, result2);
    xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/fes/2.0\">" + '\n' + "    <ogc:After>" + '\n' + "        <ogc:ValueReference>boundingBox</ogc:ValueReference>" + '\n' + "        $test" + '\n' + "    </ogc:After>" + '\n' + "</ogc:Filter>" + '\n';
    sr = new StringReader(xml);
    jb = (JAXBElement) unmarshaller.unmarshal(sr);
    result2 = (org.geotoolkit.ogc.xml.v200.FilterType) jb.getValue();
    TimeAfterType filterAfter = new TimeAfterType("boundingBox", "$test");
    expResult2 = new org.geotoolkit.ogc.xml.v200.FilterType(filterAfter);
    assertEquals(expResult2.getTemporalOps().getValue(), result2.getTemporalOps().getValue());
    assertEquals(expResult2, result2);
    xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<fes:Filter xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:gco=\"http://www.isotc211.org/2005/gco\" xmlns:gmx=\"http://www.isotc211.org/2005/gmx\" xmlns:gmi=\"http://www.isotc211.org/2005/gmi\" xmlns:gmd=\"http://www.isotc211.org/2005/gmd\" xmlns:gml=\"http://www.opengis.net/gml/3.2\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:ns8=\"http://www.opengis.net/gml\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:fes=\"http://www.opengis.net/fes/2.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\">\n" + "  <fes:PropertyIsBetween>\n" + "    <fes:ValueReference>prop</fes:ValueReference>\n" + "    <fes:LowerBoundary>\n" + "      <fes:Literal><gml:TimeInstant>\n" + "          <gml:timePosition>2002</gml:timePosition>\n" + "        </gml:TimeInstant></fes:Literal>\n" + "    </fes:LowerBoundary>\n" + "    <fes:UpperBoundary>\n" + "      <fes:Literal><gml:TimeInstant>\n" + "          <gml:timePosition>2004</gml:timePosition>\n" + "        </gml:TimeInstant></fes:Literal>\n" + "    </fes:UpperBoundary>\n" + "  </fes:PropertyIsBetween>\n" + "</fes:Filter>";
    sr = new StringReader(xml);
    jb = (JAXBElement) unmarshaller.unmarshal(sr);
    org.geotoolkit.ogc.xml.v200.FilterType result3 = (org.geotoolkit.ogc.xml.v200.FilterType) jb.getValue();
    final org.geotoolkit.gml.xml.v321.ObjectFactory gml32Factory = new org.geotoolkit.gml.xml.v321.ObjectFactory();
    final org.geotoolkit.ogc.xml.v200.ObjectFactory fesFactory = new org.geotoolkit.ogc.xml.v200.ObjectFactory();
    PropertyIsBetweenType expPes = new PropertyIsBetweenType();
    expPes.setExpression(fesFactory.createValueReference((String) "prop"));
    final LowerBoundaryType lower = new LowerBoundaryType();
    final TimeInstantType ti = new TimeInstantType("2002");
    final LiteralType lowlit = new LiteralType(gml32Factory.createTimeInstant(ti));
    lower.setExpression(fesFactory.createLiteral(lowlit));
    expPes.setLowerBoundary(lower);
    final UpperBoundaryType upper = new UpperBoundaryType();
    final TimeInstantType ti2 = new TimeInstantType("2004");
    final LiteralType upplit = new LiteralType(gml32Factory.createTimeInstant(ti2));
    upper.setExpression(fesFactory.createLiteral(upplit));
    expPes.setUpperBoundary(upper);
    org.geotoolkit.ogc.xml.v200.FilterType expResult3 = new org.geotoolkit.ogc.xml.v200.FilterType(expPes);
    assertTrue(result3.getComparisonOps().getValue() instanceof PropertyIsBetweenType);
    PropertyIsBetweenType resPes = (PropertyIsBetweenType) result3.getComparisonOps().getValue();
    assertEquals(expPes.getUpperBoundary(), resPes.getUpperBoundary());
    assertEquals(expPes.getLowerBoundary(), resPes.getLowerBoundary());
    assertEquals(expPes, resPes);
    assertEquals(expResult3.getComparisonOps().getValue(), result3.getComparisonOps().getValue());
    assertEquals(expResult3, result3);
}
Also used : OverlapsType(org.geotoolkit.ogc.xml.v110.OverlapsType) DirectPositionType(org.geotoolkit.gml.xml.v311.DirectPositionType) TimeInstantType(org.geotoolkit.gml.xml.v321.TimeInstantType) ObjectFactory(org.geotoolkit.ogc.xml.v110.ObjectFactory) StringReader(java.io.StringReader) PropertyIsBetweenType(org.geotoolkit.ogc.xml.v200.PropertyIsBetweenType) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) EnvelopeType(org.geotoolkit.gml.xml.v311.EnvelopeType) LiteralType(org.geotoolkit.ogc.xml.v200.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) TimeAfterType(org.geotoolkit.ogc.xml.v200.TimeAfterType) UpperBoundaryType(org.geotoolkit.ogc.xml.v200.UpperBoundaryType) FilterType(org.geotoolkit.ogc.xml.v110.FilterType) ContainsType(org.geotoolkit.ogc.xml.v200.ContainsType) BBOXType(org.geotoolkit.ogc.xml.v200.BBOXType) LowerBoundaryType(org.geotoolkit.ogc.xml.v200.LowerBoundaryType)

Example 17 with BBOXType

use of org.geotoolkit.ogc.xml.v110.BBOXType in project ddf by codice.

the class WfsFilterDelegate method buildBBoxType.

private JAXBElement<BBOXType> buildBBoxType(String propertyName, String wkt) {
    BBOXType bboxType = new BBOXType();
    bboxType.setExpression(filterObjectFactory.createValueReference(propertyName));
    try {
        bboxType.setAny(createEnvelope(getGeometryFromWkt(wkt)));
    } catch (ParseException e) {
        throw new UnsupportedOperationException("Unable to parse WKT Geometry [" + wkt + "]", e);
    }
    return filterObjectFactory.createBBOX(bboxType);
}
Also used : BBOXType(net.opengis.filter.v_2_0_0.BBOXType) ParseException(org.locationtech.jts.io.ParseException)

Example 18 with BBOXType

use of org.geotoolkit.ogc.xml.v110.BBOXType in project ddf by codice.

the class CswFilterFactory method createBBoxType.

private JAXBElement<BBOXType> createBBoxType(String propertyName, String wkt) {
    BBOXType bboxType = new BBOXType();
    JAXBElement<EnvelopeType> envelope = createEnvelopeType(wkt);
    bboxType.setEnvelope(envelope);
    bboxType.setPropertyName(createPropertyNameType(propertyName));
    return filterObjectFactory.createBBOX(bboxType);
}
Also used : EnvelopeType(net.opengis.gml.v_3_1_1.EnvelopeType) BBOXType(net.opengis.filter.v_1_1_0.BBOXType)

Example 19 with BBOXType

use of org.geotoolkit.ogc.xml.v110.BBOXType in project ddf by codice.

the class WfsFilterDelegateTest method testIntersectsAsBoundingBox.

@Test
public void testIntersectsAsBoundingBox() {
    WfsFilterDelegate delegate = setupFilterDelegate(SPATIAL_OPERATORS.BBOX.getValue(), new LonLatCoordinateStrategy());
    FilterType filter = delegate.intersects(Metacard.ANY_GEO, POLYGON);
    assertThat(filter.getSpatialOps().getValue(), is(instanceOf(BBOXType.class)));
    assertThat(filter.isSetLogicOps(), is(false));
    BBOXType bboxType = (BBOXType) filter.getSpatialOps().getValue();
    EnvelopeType envelope = bboxType.getEnvelope().getValue();
    DirectPositionType lowerCorner = envelope.getLowerCorner();
    assertThat("The bounding box's lower corner was null.", lowerCorner, is(notNullValue()));
    assertThat(lowerCorner.getValue(), is(asList(10.0, -10.0)));
    DirectPositionType upperCorner = envelope.getUpperCorner();
    assertThat("The bounding box's upper corner was null.", upperCorner, is(notNullValue()));
    assertThat(upperCorner.getValue(), is(asList(40.0, 30.0)));
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) EnvelopeType(net.opengis.gml.v_3_1_1.EnvelopeType) BBOXType(net.opengis.filter.v_1_1_0.BBOXType) DirectPositionType(net.opengis.gml.v_3_1_1.DirectPositionType) Test(org.junit.Test)

Example 20 with BBOXType

use of org.geotoolkit.ogc.xml.v110.BBOXType in project ddf by codice.

the class TestWfsFilterDelegate method testDisjointAsNotBBox.

@Test
public void testDisjointAsNotBBox() throws SAXException, IOException, JAXBException {
    WfsFilterDelegate delegate = setupFilterDelegate(SPATIAL_OPERATORS.BBOX.toString());
    FilterType filter = delegate.disjoint(Metacard.ANY_GEO, POLYGON);
    assertTrue(filter.getLogicOps().getValue() instanceof UnaryLogicOpType);
    UnaryLogicOpType type = (UnaryLogicOpType) filter.getLogicOps().getValue();
    assertTrue(type.getSpatialOps().getValue() instanceof BBOXType);
    assertXMLEqual(MockWfsServer.getNotBboxXmlFilter(), getXmlFromMarshaller(filter));
}
Also used : UnaryLogicOpType(net.opengis.filter.v_2_0_0.UnaryLogicOpType) FilterType(net.opengis.filter.v_2_0_0.FilterType) BBOXType(net.opengis.filter.v_2_0_0.BBOXType) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 BBOXType (net.opengis.filter.v_1_1_0.BBOXType)6 EnvelopeType (net.opengis.gml.v_3_1_1.EnvelopeType)6 JAXBElement (javax.xml.bind.JAXBElement)5 BBOXType (net.opengis.filter.v_2_0_0.BBOXType)5 DirectPositionType (net.opengis.gml.v_3_1_1.DirectPositionType)5 FilterType (net.opengis.filter.v_1_1_0.FilterType)4 FilterType (net.opengis.filter.v_2_0_0.FilterType)4 EnvelopeType (org.geotoolkit.gml.xml.v311.EnvelopeType)4 PropertyNameType (org.geotoolkit.ogc.xml.v110.PropertyNameType)4 List (java.util.List)3 BBOXType (net.opengis.fes.x20.BBOXType)3 DirectPositionType (org.geotoolkit.gml.xml.v311.DirectPositionType)3 OverlapsType (org.geotoolkit.ogc.xml.v110.OverlapsType)3 Envelope (org.locationtech.jts.geom.Envelope)3 Expression (org.opengis.filter.Expression)3 ArrayList (java.util.ArrayList)2 UnaryLogicOpType (net.opengis.filter.v_2_0_0.UnaryLogicOpType)2 BBOXType (org.geosdi.geoplatform.xml.filter.v110.BBOXType)2 TimeInstantType (org.geotoolkit.gml.xml.v321.TimeInstantType)2