Search in sources :

Example 1 with SpatialOpsType

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

the class TestWfsSource method testIntersectQuery.

@Test
public void testIntersectQuery() throws UnsupportedQueryException, WfsException, SecurityServiceException {
    setUp(ONE_GML_PROPERTY_SCHEMA, Arrays.asList(new Intersect(), new BBOX()), SRS_NAME, ONE_FEATURE, null);
    Filter intersectFilter = builder.attribute(Metacard.ANY_GEO).is().intersecting().wkt(POLYGON_WKT);
    QueryImpl intersectQuery = new QueryImpl(intersectFilter);
    intersectQuery.setPageSize(MAX_FEATURES);
    ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
    source.query(new QueryRequestImpl(intersectQuery));
    verify(mockWfs).getFeature(captor.capture());
    GetFeatureType getFeatureType = captor.getValue();
    assertMaxFeatures(getFeatureType, intersectQuery);
    assertTrue(getFeatureType.getQuery().size() == ONE_FEATURE);
    QueryType query = getFeatureType.getQuery().get(0);
    assertTrue(query.getTypeName().equals(sampleFeatures.get(0)));
    assertTrue(query.getFilter().isSetSpatialOps());
    assertTrue(query.getFilter().getSpatialOps().getValue() instanceof SpatialOpsType);
}
Also used : Intersect(ogc.schema.opengis.filter_capabilities.v_1_0_0.Intersect) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) BBOX(ogc.schema.opengis.filter_capabilities.v_1_0_0.BBOX) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SpatialOpsType(ogc.schema.opengis.filter.v_1_0_0.SpatialOpsType) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Example 2 with SpatialOpsType

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

the class OGC110Test method testFilterSpatialOverlaps.

@Test
public void testFilterSpatialOverlaps() throws JAXBException, NoSuchAuthorityCodeException, FactoryException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_SPA_OVERLAPS2);
    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);
    assertEquals(right.apply(null).toString().trim(), "LINESTRING (46.652 10.466, 47.114 11.021, 46.114 12.114, 45.725 12.523)");
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
// write test - not yet
// FilterType ft = TRANSFORMER_OGC.apply(filter);
// assertNotNull(ft.getSpatialOps());
// 
// SpatialOpsType cot = ft.getSpatialOps().getValue();
// assertEquals( ft.getLogicOps().getName().getLocalPart(), SEJAXBStatics.FILTER_SPATIAL_OVERLAPS);
// OverlapsType pibt = (OverlapsType) cot;
// 
// BinarySpatialOperator leftoptype = (BinarySpatialOperator) pibt.getComparisonOps().getValue();
// 
// PropertyNameType lf = (PropertyNameType) leftoptype.getExpression().get(0).getValue();
// LiteralType rg = (LiteralType) leftoptype.getExpression().get(1).getValue();
// 
// assertEquals(lf.getContent(), valueStr);
// assertEquals(rg.getContent().get(0).toString().trim(), valueFStr );
// 
// MARSHALLER.marshal(ft.getLogicOps(), TEST_FILE_FIL_SPA_OVERLAPS2);
}
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) BinarySpatialOperator(org.opengis.filter.BinarySpatialOperator) ValueReference(org.opengis.filter.ValueReference) Test(org.junit.Test)

Example 3 with SpatialOpsType

use of org.geotoolkit.ogc.xml.v110.SpatialOpsType 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 4 with SpatialOpsType

use of org.geotoolkit.ogc.xml.v110.SpatialOpsType 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)

Example 5 with SpatialOpsType

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

the class TestWfsSource method testBboxQuery.

@Test
public void testBboxQuery() throws UnsupportedQueryException, WfsException, SecurityServiceException {
    List<Object> bbox = new ArrayList<Object>();
    bbox.add(new BBOX());
    setUp(ONE_GML_PROPERTY_SCHEMA, bbox, SRS_NAME, ONE_FEATURE, null);
    Filter intersectFilter = builder.attribute(Metacard.ANY_GEO).is().intersecting().wkt(POLYGON_WKT);
    QueryImpl intersectQuery = new QueryImpl(intersectFilter);
    intersectQuery.setPageSize(MAX_FEATURES);
    ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
    source.query(new QueryRequestImpl(intersectQuery));
    verify(mockWfs).getFeature(captor.capture());
    GetFeatureType getFeatureType = captor.getValue();
    assertMaxFeatures(getFeatureType, intersectQuery);
    assertTrue(getFeatureType.getQuery().size() == ONE_FEATURE);
    QueryType query = getFeatureType.getQuery().get(0);
    assertTrue(query.getTypeName().equals(sampleFeatures.get(0)));
    assertTrue(query.getFilter().isSetSpatialOps());
    assertTrue(query.getFilter().getSpatialOps().getValue() instanceof SpatialOpsType);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) BBOX(ogc.schema.opengis.filter_capabilities.v_1_0_0.BBOX) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SpatialOpsType(ogc.schema.opengis.filter.v_1_0_0.SpatialOpsType) ArrayList(java.util.ArrayList) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Aggregations

Filter (org.opengis.filter.Filter)6 JAXBElement (javax.xml.bind.JAXBElement)5 Test (org.junit.Test)4 QueryImpl (ddf.catalog.operation.impl.QueryImpl)3 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)3 ArrayList (java.util.ArrayList)3 SpatialOpsType (ogc.schema.opengis.filter.v_1_0_0.SpatialOpsType)3 BBOX (ogc.schema.opengis.filter_capabilities.v_1_0_0.BBOX)3 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)3 QueryType (ogc.schema.opengis.wfs.v_1_0_0.QueryType)3 List (java.util.List)2 ComparisonOpsType (org.geotoolkit.ogc.xml.v100.ComparisonOpsType)2 LogicOpsType (org.geotoolkit.ogc.xml.v100.LogicOpsType)2 SpatialOpsType (org.geotoolkit.ogc.xml.v100.SpatialOpsType)2 SpatialOpsType (org.geotoolkit.ogc.xml.v110.SpatialOpsType)2 Expression (org.opengis.filter.Expression)2 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 Intersect (ogc.schema.opengis.filter_capabilities.v_1_0_0.Intersect)1 BoxType (org.geotoolkit.gml.xml.v212.BoxType)1