public SimpleFeatureCollection getFeatures() throws IOException { return delegate.getFeatures(); }
public SimpleFeatureCollection getFeatures(Filter filter) throws IOException { return delegate.getFeatures(filter); }
public SimpleFeatureCollection getFeatures(Query query) throws IOException { return delegate.getFeatures(query); }
query.setCoordinateSystem(sourceCRS); query.setCoordinateSystemReproject(WGS84); SimpleFeatureCollection featureCollection = featureSource.getFeatures(query);
public SimpleFeatureCollection getFeatures(Query query) throws IOException { if (query.getTypeName() == null) { query = new Query(query); ((Query) query).setTypeName(typeMap.getName()); } else if (!typeMap.getName().equals(query.getTypeName())) { throw new IOException( "Cannot query this feature source with " + query.getTypeName() + " since it serves only " + typeMap.getName()); } // GEOS-3210, if the query specifies a subset of property names we need to take that into // account SimpleFeatureType target = typeMap.getFeatureType(query); return new RetypingFeatureCollection( wrapped.getFeatures(store.retypeQuery(query, typeMap)), target); }
@Test public void testGetTypeNamesCalls() throws Exception { SimpleFeatureType orig = createNiceMock(SimpleFeatureType.class); expect(orig.getTypeName()).andReturn("orig").anyTimes(); replay(orig); SimpleFeatureType wrapped = createNiceMock(SimpleFeatureType.class); expect(wrapped.getTypeName()).andReturn("wrapped").anyTimes(); replay(wrapped); // ensure that getTypeNames() never called DataStore ds = createMock(DataStore.class); SimpleFeatureSource fs = createMock(SimpleFeatureSource.class); expect(fs.getSchema()).andReturn(orig).anyTimes(); expect(fs.getDataStore()).andReturn(ds).anyTimes(); expect(fs.getFeatures(new Query(orig.getTypeName(), Filter.INCLUDE))) .andReturn(null) .once(); replay(fs); SimpleFeatureSource rts = RetypingFeatureSource.getRetypingSource(fs, wrapped); rts.getFeatures(); } }
@Test public void testEmptySort() throws IOException, IllegalAccessException { SimpleFeatureSource fsp = getFeatureSource(SystemTestData.PRIMITIVEGEOFEATURE); Query q = new Query(); q.setSortBy(SortBy.UNSORTED); SimpleFeatureCollection fc = fsp.getFeatures(q); // the above call used to add a SortedSimpleFeatureCollection wrapper that in turn killed // some visit optimizations while (fc instanceof DecoratingFeatureCollection) { assertThat(fc, not(instanceOf(SortedSimpleFeatureCollection.class))); Field field = FieldUtils.getDeclaredField(SortedSimpleFeatureCollection.class, "delegate"); field.setAccessible(true); Object delegate = field.get(fc); fc = (SimpleFeatureCollection) delegate; } }
query.setCoordinateSystem(sourceCRS); query.setCoordinateSystemReproject(WGS84); SimpleFeatureCollection featureCollection = featureSource.getFeatures(query);
try { SimpleFeatureCollection fc = source.getFeatures(newQuery);
@Test public void testSimpleRename() throws IOException { SimpleFeatureSource fs = store.getFeatureSource(BUILDINGS.getLocalPart()); SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(fs.getSchema()); tb.setName("houses"); SimpleFeatureType target = tb.buildFeatureType(); SimpleFeatureSource retyped = RetypingFeatureSource.getRetypingSource(fs, target); assertTrue(retyped instanceof SimpleFeatureLocking); assertEquals(target, retyped.getSchema()); assertEquals(target, ((DataStore) retyped.getDataStore()).getSchema("houses")); assertEquals(target, retyped.getFeatures().getSchema()); SimpleFeatureIterator it = retyped.getFeatures().features(); SimpleFeature f = it.next(); it.close(); assertEquals(target, f.getType()); }
Filter fidFilter = ff.id(Collections.singleton(ff.featureId(fid))); SimpleFeatureIterator it = retyped.getFeatures(fidFilter).features(); assertTrue(it.hasNext()); SimpleFeature f = it.next();
@Test public void testFeautureSourceFidFilter() throws Exception { // grab the last feature in the collection (there are more than one) SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); // build a filter that will retrieve that feature only FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); final String fid = RENAMED + ".1107531701011"; Filter fidFilter = ff.id(Collections.singleton(ff.featureId(fid))); SimpleFeatureCollection fc = fs.getFeatures(new Query(RENAMED, fidFilter)); assertEquals(RENAMED, fc.getSchema().getName().getLocalPart()); assertEquals(1, fc.size()); FeatureIterator<SimpleFeature> it = fc.features(); assertTrue(it.hasNext()); SimpleFeature sf = it.next(); assertFalse(it.hasNext()); it.close(); assertEquals(fid, sf.getID()); }
@Test public void testQueryWithPropertyNames() throws Exception { // check the schemas in feature source and feature collection SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); Query q = new Query(RENAMED, Filter.INCLUDE, new String[] {"ADDRESS"}); FeatureCollection<SimpleFeatureType, SimpleFeature> fc = fs.getFeatures(q); assertEquals(1, fc.getSchema().getAttributeCount()); // make sure the feature schema is good as well FeatureIterator<SimpleFeature> it = fc.features(); SimpleFeature sf = it.next(); it.close(); assertEquals(1, sf.getAttributeCount()); assertNull(sf.getAttribute("FID")); assertNotNull(sf.getAttribute("ADDRESS")); } }
@Test public void testFeautureSourceFidFilter() throws Exception { // grab the last feature in the collection (there are more than one) SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); // build a filter that will retrieve that feature only FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); final String fid = RENAMED + ".f001"; Filter fidFilter = ff.id(Collections.singleton(ff.featureId(fid))); SimpleFeatureCollection fc = fs.getFeatures(new Query(RENAMED, fidFilter)); assertEquals(RENAMED, fc.getSchema().getName().getLocalPart()); assertEquals(1, fc.size()); FeatureIterator<SimpleFeature> it = fc.features(); assertTrue(it.hasNext()); SimpleFeature sf = it.next(); assertFalse(it.hasNext()); it.close(); assertEquals(fid, sf.getID()); }
@Test public void testGetFeaturesFeatureSource() throws Exception { // check the schemas in feature source and feature collection SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); assertEquals(RENAMED, fs.getSchema().getName().getLocalPart()); SimpleFeatureCollection fc = fs.getFeatures(); assertEquals(RENAMED, fc.getSchema().getName().getLocalPart()); assertTrue(fc.size() > 0); // make sure the feature schema is good as well FeatureIterator<SimpleFeature> it = fc.features(); SimpleFeature sf = it.next(); it.close(); assertEquals(RENAMED, sf.getFeatureType().getName().getLocalPart()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); }
store.createSchema(schema); SimpleFeatureStore featureStore = (SimpleFeatureStore) store.getFeatureSource("pgeo"); featureStore.addFeatures(fsp.getFeatures());
@Test public void testGetFeaturesFeatureSource() throws Exception { // check the schemas in feature source and feature collection SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); assertEquals(primitive, fs.getSchema()); SimpleFeatureCollection fc = fs.getFeatures(); assertEquals(primitive, fc.getSchema()); assertTrue(fc.size() > 0); // make sure the feature schema is good as well FeatureIterator<SimpleFeature> it = fc.features(); SimpleFeature sf = it.next(); it.close(); assertEquals(primitive, sf.getFeatureType()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); // check mappings occurred assertEquals("description-f001", sf.getAttribute("description")); assertTrue( new WKTReader() .read("MULTIPOINT(39.73245 2.00342)") .equalsExact((Geometry) sf.getAttribute("pointProperty"))); assertEquals(Long.valueOf(155), sf.getAttribute("intProperty")); assertNull(sf.getAttribute("newProperty")); }
public void testMemoryDataStoreAddFeatures() throws Exception { MemoryDataStore store = new MemoryDataStore(); assertNotNull(store); store.addFeatures(DataUtilities.collection(roadFeatures)); assertStoreHasFeatureType(store, "road"); SimpleFeatureSource featureSource = store.getFeatureSource("road"); SimpleFeatureCollection features = featureSource.getFeatures(); int size = features.size(); assertEquals(roadFeatures.length, size); } /*
public void testNegated() throws IOException { FilterFactory ff = dataStore.getFilterFactory(); Function function = ff.function( "in", ff.property(aname("intProperty")), ff.literal("1"), ff.literal("2")); Filter filter = ff.not(ff.equal(function, ff.literal("true"), false)); SimpleFeatureSource fs = dataStore.getFeatureSource(tname("ft1")); SimpleFeatureCollection fc = fs.getFeatures(filter); assertEquals(getCaseInsensitiveSet("ft1.0"), collectFeatureIds(fc)); }
public void testGetFeatureSourceRiver() throws NoSuchElementException, IOException { SimpleFeatureSource river = data.getFeatureSource("river"); assertSame(riverType, river.getSchema()); assertSame(data, river.getDataStore()); SimpleFeatureCollection all = river.getFeatures(); assertEquals(2, all.size()); assertEquals(riverBounds, all.getBounds()); assertTrue("rivers", covers(all.features(), riverFeatures)); SimpleFeatureCollection expected = DataUtilities.collection(riverFeatures); assertCovers("all", expected, all); assertEquals(riverBounds, all.getBounds()); }