Search in sources :

Example 21 with Query

use of org.geotools.data.Query in project incubator-rya by apache.

the class GeoWaveFeatureReaderTest method testFidFilterQuery.

@Test
public void testFidFilterQuery() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
    final String fidsString = fids.stream().collect(Collectors.joining("','", "'", "'"));
    final Filter filter = ECQL.toFilter("IN (" + fidsString + ")");
    final Query query = new Query("GeoWaveFeatureReaderTest", filter, new String[] { "geometry", "pid" });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertTrue(count == fids.size());
}
Also used : Query(org.geotools.data.Query) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 22 with Query

use of org.geotools.data.Query in project incubator-rya by apache.

the class GeoWaveFeatureReaderTest method testPidFilterQuery.

@Test
public void testPidFilterQuery() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
    // Filter it so that it only queries for everything but the first pid.
    // There's only 2 pids total so it should just return the second one.
    final String pidsString = pids.subList(1, pids.size()).stream().collect(Collectors.joining("','", "'", "'"));
    final Filter filter = ECQL.toFilter("pid IN (" + pidsString + ")");
    final Query query = new Query("GeoWaveFeatureReaderTest", filter, new String[] { "geometry", "pid" });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertTrue(count == pids.size() - 1);
}
Also used : Query(org.geotools.data.Query) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 23 with Query

use of org.geotools.data.Query in project polymap4-core by Polymap4.

the class PipelineFeatureSource method getReaderInternal.

@Override
@SuppressWarnings("hiding")
protected FeatureReader<SimpleFeatureType, SimpleFeature> getReaderInternal(Query query) throws IOException {
    log.debug("query= " + query);
    // assert query.getFilter() != null : "No filter in query.";
    if (query.getFilter() == null) {
        log.warn("Filter is NULL -> changing to EXCLUDE to prevent unwanted loading of all features! Use INCLUDE to get all.");
        query = new Query(query);
        query.setFilter(Filter.EXCLUDE);
    }
    return new PipelineAsyncFeatureReader(this, query, sessionContext);
}
Also used : Query(org.geotools.data.Query)

Example 24 with Query

use of org.geotools.data.Query in project polymap4-core by Polymap4.

the class RFeatureStore method removeFeatures.

@Override
public void removeFeatures(Filter filter) throws IOException {
    try {
        startModification();
        RFeatureCollection features = getFeatures(new Query(null, filter));
        for (RFeature feature : features) {
            txState.updater().remove(feature.state);
        }
        completeModification(true);
    } catch (IOException e) {
        completeModification(false);
        throw e;
    } catch (Throwable e) {
        log.warn("", e);
        completeModification(false);
        throw new RuntimeException(e);
    }
}
Also used : Query(org.geotools.data.Query) IOException(java.io.IOException)

Example 25 with Query

use of org.geotools.data.Query in project polymap4-core by Polymap4.

the class PipelineReadTest method testCount.

@Test
public void testCount() throws IOException {
    PipelineFeatureSource fs = pipeDs.getFeatureSource();
    Query query = Query.ALL;
    assertEquals(expected.COUNT, fs.getCount(query));
    query = new Query(null, Filter.INCLUDE);
    assertEquals(expected.COUNT, fs.getCount(query));
    query = new Query(null, Filter.EXCLUDE);
    assertEquals(0, /*origFs.getCount( query )*/
    fs.getCount(query));
}
Also used : PipelineFeatureSource(org.polymap.core.data.PipelineFeatureSource) Query(org.geotools.data.Query) Test(org.junit.Test)

Aggregations

Query (org.geotools.data.Query)34 SimpleFeature (org.opengis.feature.simple.SimpleFeature)18 Test (org.junit.Test)16 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)13 HashMap (java.util.HashMap)6 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)6 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)6 Filter (org.opengis.filter.Filter)6 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)6 Geometry (com.vividsolutions.jts.geom.Geometry)5 DefaultTransaction (org.geotools.data.DefaultTransaction)5 Transaction (org.geotools.data.Transaction)5 Polygon (com.vividsolutions.jts.geom.Polygon)4 IOException (java.io.IOException)4 Map (java.util.Map)4 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)4 ArrayList (java.util.ArrayList)3 FileDataStoreFactorySpi (org.geotools.data.FileDataStoreFactorySpi)3 ShapefileDataStore (org.geotools.data.shapefile.ShapefileDataStore)3 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)3