Search in sources :

Example 1 with Query

use of org.geotools.data.Query in project GeoGig by boundlessgeo.

the class WorkingTreeTest method testInsertPagingFeatureSource.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testInsertPagingFeatureSource() throws Exception {
    assertEquals(2, super.getGeogig().getPlatform().availableProcessors());
    final List<SimpleFeature> features = ImmutableList.of((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3);
    MemoryDataStore store = new MemoryDataStore();
    store.addFeatures(features);
    final QueryCapabilities caps = mock(QueryCapabilities.class);
    when(caps.isOffsetSupported()).thenReturn(true);
    FeatureSource source = new ForwardingFeatureSource(store.getFeatureSource(pointsName)) {

        @Override
        public QueryCapabilities getQueryCapabilities() {
            return caps;
        }

        @Override
        public FeatureCollection getFeatures(Query query) throws IOException {
            Integer startIndex = query.getStartIndex();
            if (startIndex == null) {
                return super.getFeatures();
            }
            int toIndex = (int) Math.min((long) startIndex + query.getMaxFeatures(), features.size());
            List<SimpleFeature> result = features.subList(startIndex, toIndex);
            return DataUtilities.collection(result);
        }
    };
    assertTrue(source.getQueryCapabilities().isOffsetSupported());
    String treePath = "target_typename";
    workTree.insert(treePath, source, Query.ALL, LISTENER);
    assertEquals(3, workTree.countUnstaged(treePath).featureCount());
}
Also used : ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) FeatureSource(org.geotools.data.FeatureSource) QueryCapabilities(org.geotools.data.QueryCapabilities) Query(org.geotools.data.Query) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 2 with Query

use of org.geotools.data.Query in project GeoGig by boundlessgeo.

the class GeoGigFeatureSourceTest method testGetBoundsQuery.

@Test
public void testGetBoundsQuery() throws Exception {
    ReferencedEnvelope bounds;
    Filter filter;
    filter = ff.id(Collections.singleton(ff.featureId(RepositoryTestCase.idP2)));
    bounds = pointsSource.getBounds(new Query(pointsName, filter));
    assertEquals(boundsOf(points2), bounds);
    ReferencedEnvelope queryBounds = boundsOf(points1, points2);
    Polygon geometry = JTS.toGeometry(queryBounds);
    filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
    bounds = pointsSource.getBounds(new Query(pointsName, filter));
    assertEquals(boundsOf(points1, points2), bounds);
    ReferencedEnvelope transformedQueryBounds;
    CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:3857");
    transformedQueryBounds = queryBounds.transform(queryCrs, true);
    geometry = JTS.toGeometry(transformedQueryBounds);
    geometry.setUserData(queryCrs);
    filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
    bounds = pointsSource.getBounds(new Query(pointsName, filter));
    assertEquals(boundsOf(points1, points2), bounds);
    filter = ECQL.toFilter("sp = 'StringProp2_3' OR ip = 2000");
    bounds = linesSource.getBounds(new Query(linesName, filter));
    assertEquals(boundsOf(lines3, lines2), bounds);
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Query(org.geotools.data.Query) Filter(org.opengis.filter.Filter) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test)

Example 3 with Query

use of org.geotools.data.Query in project GeoGig by boundlessgeo.

the class GeoGigFeatureSourceTest method testGetCount.

@Test
public void testGetCount() throws Exception {
    assertEquals(3, pointsSource.getCount(Query.ALL));
    assertEquals(3, linesSource.getCount(Query.ALL));
    Filter filter;
    filter = ff.id(Collections.singleton(ff.featureId(RepositoryTestCase.idP2)));
    assertEquals(1, pointsSource.getCount(new Query(pointsName, filter)));
    ReferencedEnvelope queryBounds = boundsOf(points1, points2);
    Polygon geometry = JTS.toGeometry(queryBounds);
    filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
    assertEquals(2, pointsSource.getCount(new Query(pointsName, filter)));
    ReferencedEnvelope transformedQueryBounds;
    CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:3857");
    transformedQueryBounds = queryBounds.transform(queryCrs, true);
    geometry = JTS.toGeometry(transformedQueryBounds);
    geometry.setUserData(queryCrs);
    filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
    assertEquals(2, pointsSource.getCount(new Query(pointsName, filter)));
    filter = ECQL.toFilter("sp = 'StringProp2_3' OR ip = 2000");
    assertEquals(2, linesSource.getCount(new Query(linesName, filter)));
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Query(org.geotools.data.Query) Filter(org.opengis.filter.Filter) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test)

Example 4 with Query

use of org.geotools.data.Query in project GeoGig by boundlessgeo.

the class ImportOp method getFeatureSource.

@SuppressWarnings({ "rawtypes", "unchecked" })
private FeatureSource getFeatureSource(String typeName) {
    FeatureSource featureSource;
    try {
        featureSource = dataStore.getFeatureSource(typeName);
    } catch (Exception e) {
        throw new GeoToolsOpException(StatusCode.UNABLE_TO_GET_FEATURES);
    }
    return new ForwardingFeatureSource(featureSource) {

        @Override
        public FeatureCollection getFeatures(Query query) throws IOException {
            final FeatureCollection features = super.getFeatures(query);
            return new ForwardingFeatureCollection(features) {

                @Override
                public FeatureIterator features() {
                    final FeatureType featureType = getSchema();
                    final String fidPrefix = featureType.getName().getLocalPart() + ".";
                    FeatureIterator iterator = delegate.features();
                    return new FidAndFtReplacerIterator(iterator, fidAttribute, fidPrefix, (SimpleFeatureType) featureType);
                }
            };
        }
    };
}
Also used : FeatureIterator(org.geotools.feature.FeatureIterator) ForwardingFeatureIterator(org.locationtech.geogig.api.data.ForwardingFeatureIterator) ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) JDBCFeatureSource(org.geotools.jdbc.JDBCFeatureSource) FeatureSource(org.geotools.data.FeatureSource) ResolveFeatureType(org.locationtech.geogig.api.plumbing.ResolveFeatureType) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureType(org.opengis.feature.type.FeatureType) Query(org.geotools.data.Query) ForwardingFeatureCollection(org.locationtech.geogig.api.data.ForwardingFeatureCollection) ForwardingFeatureCollection(org.locationtech.geogig.api.data.ForwardingFeatureCollection) FeatureCollection(org.geotools.feature.FeatureCollection) ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 5 with Query

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

the class GeoWaveFeatureReaderTest method setup.

@Before
public void setup() throws SchemaException, CQLException, Exception {
    setupConf();
    try (final GeoWaveGeoIndexer indexer = new GeoWaveGeoIndexer()) {
        indexer.setConf(conf);
        dataStore = indexer.getGeoToolsDataStore();
        // Clear old data
        indexer.purge(conf);
        type = DataUtilities.createType("GeoWaveFeatureReaderTest", "geometry:Geometry:srid=4326,start:Date,end:Date,pop:java.lang.Long,pid:String");
        dataStore.createSchema(type);
        stime = DateUtilities.parseISO("2005-05-15T20:32:56Z");
        etime = DateUtilities.parseISO("2005-05-20T20:32:56Z");
        final Transaction transaction1 = new DefaultTransaction();
        final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1);
        assertFalse(writer.hasNext());
        SimpleFeature newFeature = writer.next();
        newFeature.setAttribute("pop", Long.valueOf(100));
        newFeature.setAttribute("pid", "a" + UUID.randomUUID().toString());
        newFeature.setAttribute("start", stime);
        newFeature.setAttribute("end", etime);
        newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));
        fids.add(newFeature.getID());
        pids.add(newFeature.getAttribute("pid").toString());
        writer.write();
        newFeature = writer.next();
        newFeature.setAttribute("pop", Long.valueOf(101));
        newFeature.setAttribute("pid", "b" + UUID.randomUUID().toString());
        newFeature.setAttribute("start", etime);
        newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(28.25, 41.25)));
        fids.add(newFeature.getID());
        pids.add(newFeature.getAttribute("pid").toString());
        writer.write();
        writer.close();
        transaction1.commit();
        transaction1.close();
        query = new Query("GeoWaveFeatureReaderTest", ECQL.toFilter("IN ('" + fids.get(0) + "')"), new String[] { "geometry", "pid" });
    }
}
Also used : Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Query(org.geotools.data.Query) Coordinate(com.vividsolutions.jts.geom.Coordinate) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Before(org.junit.Before)

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