Search in sources :

Example 1 with Contains

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

the class LuceneQueryDialect method supports.

public static boolean supports(Filter _filter) {
    final List notSupported = new ArrayList();
    _filter.accept(new DefaultFilterVisitor() {

        public Object visit(Beyond filter, Object data) {
            notSupported.add(filter);
            return super.visit(filter, data);
        }

        public Object visit(Contains filter, Object data) {
            notSupported.add(filter);
            return super.visit(filter, data);
        }

        public Object visit(Crosses filter, Object data) {
            notSupported.add(filter);
            return super.visit(filter, data);
        }

        public Object visit(Disjoint filter, Object data) {
            notSupported.add(filter);
            return super.visit(filter, data);
        }

        public Object visit(Divide expression, Object data) {
            notSupported.add(expression);
            return super.visit(expression, data);
        }

        public Object visit(DWithin filter, Object data) {
            notSupported.add(filter);
            return super.visit(filter, data);
        }

        public Object visit(org.opengis.filter.expression.Function expression, Object data) {
            notSupported.add(expression);
            return super.visit(expression, data);
        }

        public Object visit(Intersects filter, Object data) {
            notSupported.add(filter);
            return super.visit(filter, data);
        }

        public Object visit(Multiply expression, Object data) {
            notSupported.add(expression);
            return super.visit(expression, data);
        }

        public Object visit(Overlaps filter, Object data) {
            notSupported.add(filter);
            return super.visit(filter, data);
        }

        public Object visit(Subtract expression, Object data) {
            notSupported.add(expression);
            return super.visit(expression, data);
        }

        public Object visit(Touches filter, Object data) {
            notSupported.add(filter);
            return super.visit(filter, data);
        }

        public Object visit(Within filter, Object data) {
            notSupported.add(filter);
            return super.visit(filter, data);
        }
    }, notSupported);
    return notSupported.isEmpty();
}
Also used : Overlaps(org.opengis.filter.spatial.Overlaps) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) ArrayList(java.util.ArrayList) Beyond(org.opengis.filter.spatial.Beyond) Divide(org.opengis.filter.expression.Divide) Crosses(org.opengis.filter.spatial.Crosses) DWithin(org.opengis.filter.spatial.DWithin) Intersects(org.opengis.filter.spatial.Intersects) Multiply(org.opengis.filter.expression.Multiply) Contains(org.opengis.filter.spatial.Contains) DWithin(org.opengis.filter.spatial.DWithin) Within(org.opengis.filter.spatial.Within) Disjoint(org.opengis.filter.spatial.Disjoint) Subtract(org.opengis.filter.expression.Subtract) Touches(org.opengis.filter.spatial.Touches) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with Contains

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

the class OpenSearchFilterVisitorTest method testMultipleFiltersWhereOneFilterIsIgnored.

/**
 * Test that other {@link Filter}s are still visited when a {@link Filter} is ignored. The {@link
 * Filter}s in this test are the same as {@link #testMultipleFilters} except that the temporal
 * criteria is from {@link #testNotModifiedTemporalFilter()}.
 */
@Test
public void testMultipleFiltersWhereOneFilterIsIgnored() {
    During duringFilter = (During) geotoolsFilterBuilder.attribute(SOME_ATTRIBUTE_NAME).during().dates(START_DATE, END_DATE);
    Contains containsFilter = (Contains) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).containing().wkt(WKT_POLYGON);
    And andFilter = geotoolsFilterBuilder.allOf(duringFilter, containsFilter);
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    openSearchFilterVisitorObject.setCurrentNest(NestedTypes.AND);
    OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(andFilter, openSearchFilterVisitorObject);
    assertThat(result.getTemporalSearch(), is(nullValue()));
    assertThat(result.getGeometrySearches(), contains(hasToString(is(WKT_POLYGON))));
}
Also used : And(org.opengis.filter.And) Contains(org.opengis.filter.spatial.Contains) During(org.opengis.filter.temporal.During) Test(org.junit.Test)

Example 3 with Contains

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

the class OpenSearchFilterVisitorTest method testNotLocationSpatialFilter.

/**
 * Spatial {@link Filter}s for attributes other than {@value SPATIAL_ATTRIBUTE_NAME} should be
 * ignored.
 */
@Test
public void testNotLocationSpatialFilter() {
    Contains containsFilter = (Contains) geotoolsFilterBuilder.attribute(SOME_ATTRIBUTE_NAME).containing().wkt(WKT_POLYGON);
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    openSearchFilterVisitorObject.setCurrentNest(NestedTypes.AND);
    OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(containsFilter, openSearchFilterVisitorObject);
    assertThat(result.getGeometrySearches(), is(empty()));
}
Also used : Contains(org.opengis.filter.spatial.Contains) Test(org.junit.Test)

Example 4 with Contains

use of org.opengis.filter.spatial.Contains in project coastal-hazards by USGS-CIDA.

the class FeatureCollectionExportTest method splitterTest.

@Test
// for now
@Ignore
public void splitterTest() throws Exception {
    // get geometry
    HttpComponentsWFSClient wfs1 = new HttpComponentsWFSClient();
    wfs1.setupDatastoreFromEndpoint("http://cida-wiwsc-cchdev:8081/geoserver/wfs");
    FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
    PropertyIsEqualTo equals = filterFactory.equals(filterFactory.property("STATEFP"), filterFactory.literal(37));
    SimpleFeatureCollection featureCollection = wfs1.getFeatureCollection("splitter:tl_2013_coastal_states", equals);
    SimpleFeatureIterator features = featureCollection.features();
    // only deal with one
    Geometry geom = null;
    if (features.hasNext()) {
        SimpleFeature next = features.next();
        geom = (Geometry) next.getDefaultGeometry();
    }
    // then use geometry as filter
    HttpComponentsWFSClient wfs2 = new HttpComponentsWFSClient();
    wfs2.setupDatastoreFromEndpoint("http://cida-wiwsc-cchdev:8081/geoserver/wfs");
    FilterFactory2 filterFactory2 = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
    Contains contains = filterFactory2.contains(filterFactory2.property("the_geom"), filterFactory2.literal(geom));
    SimpleFeatureCollection featureCollection2 = wfs2.getFeatureCollection("proxied:atl_cvi", contains);
    SimpleFeatureType schema = GMLStreamingFeatureCollection.unwrapSchema(featureCollection2.getSchema());
    FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory("shp");
    Map datastoreConfig = new HashMap<>();
    datastoreConfig.put("url", FileUtils.getFile(FileUtils.getTempDirectory(), "splitter.shp").toURI().toURL());
    ShapefileDataStore shpfileDataStore = (ShapefileDataStore) factory.createNewDataStore(datastoreConfig);
    shpfileDataStore.createSchema(schema);
    shpfileDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
    SimpleFeatureStore featureStore = (SimpleFeatureStore) shpfileDataStore.getFeatureSource();
    Transaction t = new DefaultTransaction();
    // Copied directly from Import process
    featureStore.setTransaction(t);
    Query query = new Query();
    query.setCoordinateSystem(DefaultGeographicCRS.WGS84);
    SimpleFeatureIterator fi = featureCollection2.features();
    SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema);
    while (fi.hasNext()) {
        SimpleFeature source = fi.next();
        fb.reset();
        for (AttributeDescriptor desc : schema.getAttributeDescriptors()) {
            fb.set(desc.getName(), source.getAttribute(desc.getName()));
        }
        SimpleFeature target = fb.buildFeature(null);
        target.setDefaultGeometry(source.getDefaultGeometry());
        featureStore.addFeatures(DataUtilities.collection(target));
    }
    t.commit();
    t.close();
}
Also used : ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) Query(org.geotools.data.Query) HashMap(java.util.HashMap) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Geometry(com.vividsolutions.jts.geom.Geometry) FileDataStoreFactorySpi(org.geotools.data.FileDataStoreFactorySpi) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) Contains(org.opengis.filter.spatial.Contains) FilterFactory2(org.opengis.filter.FilterFactory2) HashMap(java.util.HashMap) Map(java.util.Map) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Contains

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

the class OpenSearchFilterVisitorTest method testContains.

@Test
public void testContains() {
    Contains containsFilter = (Contains) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).containing().wkt(WKT_POLYGON);
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    openSearchFilterVisitorObject.setCurrentNest(NestedTypes.AND);
    OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(containsFilter, openSearchFilterVisitorObject);
    assertThat(result.getGeometrySearches(), contains(hasToString(is(WKT_POLYGON))));
}
Also used : Contains(org.opengis.filter.spatial.Contains) Test(org.junit.Test)

Aggregations

Contains (org.opengis.filter.spatial.Contains)11 Test (org.junit.Test)10 And (org.opengis.filter.And)2 DWithin (org.opengis.filter.spatial.DWithin)2 Intersects (org.opengis.filter.spatial.Intersects)2 During (org.opengis.filter.temporal.During)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 DefaultTransaction (org.geotools.data.DefaultTransaction)1 FileDataStoreFactorySpi (org.geotools.data.FileDataStoreFactorySpi)1 Query (org.geotools.data.Query)1 Transaction (org.geotools.data.Transaction)1 ShapefileDataStore (org.geotools.data.shapefile.ShapefileDataStore)1 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)1 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)1 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1