Search in sources :

Example 1 with BBOX

use of org.opengis.filter.spatial.BBOX in project ddf by codice.

the class TestPubSubOgcFilter method testGeospatialFeatureEvaluate.

@Test
@Ignore
public void testGeospatialFeatureEvaluate() throws TransformerException {
    SimpleFeature feature = generateSampleFeature();
    FilterFactoryImpl filterFactory = new FilterFactoryImpl();
    BBOX bboxFilter = filterFactory.bbox("geo", -114, 10, -110, 30, DefaultGeographicCRS.WGS84.toString());
    assertTrue(bboxFilter.evaluate(feature));
    BBOX bboxFilter1 = filterFactory.bbox("geo", -110, 10, 0, 30, DefaultGeographicCRS.WGS84.toString());
    assertFalse(bboxFilter1.evaluate(feature));
}
Also used : BBOX(org.opengis.filter.spatial.BBOX) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with BBOX

use of org.opengis.filter.spatial.BBOX in project ddf by codice.

the class TestCswRecordMapperFilterVisitor method testVisitBBox.

@Test
public void testVisitBBox() {
    BBOX filter = factory.bbox(attrExpr, 0, 0, 10, 20, "EPSG:4269");
    String polygon = "POLYGON ((0 0, 0 20, 10 20, 10 0, 0 0))";
    Object obj = visitor.visit(filter, null);
    assertThat(obj, instanceOf(Within.class));
    Within duplicate = (Within) obj;
    assertThat(duplicate.getExpression1(), is(attrExpr));
    assertThat(duplicate.getExpression2().toString(), is(polygon));
}
Also used : BBOX(org.opengis.filter.spatial.BBOX) DWithin(org.opengis.filter.spatial.DWithin) Within(org.opengis.filter.spatial.Within) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 3 with BBOX

use of org.opengis.filter.spatial.BBOX in project polymap4-core by Polymap4.

the class FilterUtils method createBBoxFilters.

/**
 * Creates the bounding box filters (one for each geometric attribute)
 * needed to query a <code>MapLayer</code>'s feature source to return just
 * the features for the target rendering extent
 *
 * @param schema the layer's feature source schema
 * @param attributes set of needed attributes or null.
 * @param bbox the expression holding the target rendering bounding box
 * @return an or'ed list of bbox filters, one for each geometric attribute
 *         in <code>attributes</code>. If there are just one geometric
 *         attribute, just returns its corresponding
 *         <code>GeometryFilter</code>.
 * @throws IllegalFilterException if something goes wrong creating the
 *         filter
 */
public static Filter createBBoxFilters(SimpleFeatureType schema, String[] attributes, Envelope bbox) throws IllegalFilterException {
    if (attributes == null) {
        List<AttributeDescriptor> ats = schema.getAttributeDescriptors();
        int length = ats.size();
        attributes = new String[length];
        for (int t = 0; t < length; t++) {
            attributes[t] = ats.get(t).getLocalName();
        }
    }
    Filter filter = Filter.INCLUDE;
    for (int j = 0; j < attributes.length; j++) {
        AttributeDescriptor attType = schema.getDescriptor(attributes[j]);
        if (attType == null) {
            throw new IllegalFilterException(new StringBuffer("Could not find '").append(attributes[j] + "' in the FeatureType (").append(schema.getTypeName()).append(")").toString());
        }
        if (attType instanceof GeometryDescriptor) {
            BBOX gfilter = filterFactory.bbox(attType.getLocalName(), bbox.getMinX(), bbox.getMinY(), bbox.getMaxX(), bbox.getMaxY(), null);
            if (filter == Filter.INCLUDE) {
                filter = gfilter;
            } else {
                filter = filterFactory.or(filter, gfilter);
            }
        }
    }
    return filter;
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) Filter(org.opengis.filter.Filter) BBOX(org.opengis.filter.spatial.BBOX) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) IllegalFilterException(org.geotools.filter.IllegalFilterException)

Aggregations

BBOX (org.opengis.filter.spatial.BBOX)3 Test (org.junit.Test)2 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)1 FilterFactoryImpl (org.geotools.filter.FilterFactoryImpl)1 IllegalFilterException (org.geotools.filter.IllegalFilterException)1 Ignore (org.junit.Ignore)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)1 GeometryDescriptor (org.opengis.feature.type.GeometryDescriptor)1 Filter (org.opengis.filter.Filter)1 DWithin (org.opengis.filter.spatial.DWithin)1 Within (org.opengis.filter.spatial.Within)1