public void testBounds() { MemoryFeatureCollection rivers = new MemoryFeatureCollection(riverType); ReferencedEnvelope expected = new ReferencedEnvelope(); for (int i = 0; i < riverFeatures.length; i++) { rivers.add(riverFeatures[i]); expected.include(riverFeatures[i].getBounds()); } assertEquals(riverFeatures.length, rivers.size()); // Should not throw an UnsupportedOperationException assertNotNull(rivers.getBounds()); assertEquals(expected, rivers.getBounds()); }
public void testAddAll() { MemoryFeatureCollection rivers = new MemoryFeatureCollection(riverType); rivers.addAll(Arrays.asList(riverFeatures)); }
/** Calculates the bounds of the features without caching. */ @Override public ReferencedEnvelope getBounds() { return DataUtilities.bounds(features()); }
public void testAdd() { MemoryFeatureCollection rivers = new MemoryFeatureCollection(riverType); for (int i = 0; i < riverFeatures.length; i++) { rivers.add(riverFeatures[i]); } assertEquals(riverFeatures.length, rivers.size()); }
protected void addFeature( int id, Date time, Double elevation, Date referenceTime, Double scanningAngle) throws IOException { FeatureTypeInfo timeElevationCustom = getCatalog().getFeatureTypeByName(TIME_ELEVATION_CUSTOM.getLocalPart()); FeatureStore fs = (FeatureStore) timeElevationCustom.getFeatureSource(null, null); SimpleFeatureType type = (SimpleFeatureType) timeElevationCustom.getFeatureType(); MemoryFeatureCollection coll = new MemoryFeatureCollection(type); StringBuffer content = new StringBuffer(); content.append(id); content.append('|'); content.append(time.toString()); content.append('|'); content.append(elevation); content.append('|'); content.append(referenceTime.toString()); content.append('|'); content.append(scanningAngle); SimpleFeature f = DataUtilities.createFeature(type, content.toString()); coll.add(f); org.geotools.data.Transaction tx = fs.getTransaction(); fs.addFeatures(coll); tx.commit(); }
@Override public boolean addAll(Collection<? extends SimpleFeature> c) { boolean changed = false; for (SimpleFeature feature : c) { boolean added = add(feature); if (!changed && added) { changed = true; } } return changed; }
public void testResources() { Object[] array = roads.toArray(); assertEquals(roads.size(), array.length); SimpleFeatureIterator i = roads.features(); try { assertTrue(i.hasNext()); } finally { i.close(); } try { assertFalse(i.hasNext()); fail("should be closed"); } catch (IllegalStateException closed) { } i = roads.features(); try { assertTrue(i.hasNext()); } finally { i.close(); } try { assertFalse(i.hasNext()); fail("should be closed"); } catch (IllegalStateException closed) { } }
public void testSubCollection() { int count = 0; SimpleFeatureIterator it = roads.features(); try { while (it.hasNext()) { SimpleFeature feature = it.next(); if (rd12Filter.evaluate(feature)) { count++; } } } finally { it.close(); } SimpleFeatureCollection sub = roads.subCollection(rd12Filter); assertEquals(count, sub.size()); }
/** This feature collection is still implementing Collection so we best check it works */ public void testIterator() throws Exception { int count = 0; Iterator<SimpleFeature> it = roads.iterator(); try { while (it.hasNext()) { @SuppressWarnings("unused") SimpleFeature feature = it.next(); count++; } } finally { DataUtilities.close(it); } assertEquals(roads.size(), count); count = 0; FilteredIterator<SimpleFeature> filteredIterator = new FilteredIterator<SimpleFeature>(roads, rd12Filter); try { while (filteredIterator.hasNext()) { @SuppressWarnings("unused") SimpleFeature feature = filteredIterator.next(); count++; } } finally { filteredIterator.close(); } assertEquals(expected(rd12Filter), count); }
public void testSize() { assertEquals(roadFeatures.length, roads.size()); }
public void testSubSubCollection() { SimpleFeatureCollection sub = roads.subCollection(rd12Filter); SimpleFeatureCollection subsub = sub.subCollection(rd1Filter); assertEquals(1, subsub.size()); }
/** * Calculates the bounds of the features without caching. */ @Override public ReferencedEnvelope getBounds() { BoundsVisitor bounds = new BoundsVisitor(); accepts(bounds, new NullProgressListener()); return bounds.getBounds(); }
protected void addFeature(int id, Date time, Double elevation) throws IOException { FeatureTypeInfo timeWithStartEnd = getCatalog().getFeatureTypeByName(TIME_WITH_START_END.getLocalPart()); FeatureStore fs = (FeatureStore) timeWithStartEnd.getFeatureSource(null, null); SimpleFeatureType type = (SimpleFeatureType) timeWithStartEnd.getFeatureType(); MemoryFeatureCollection coll = new MemoryFeatureCollection(type); StringBuffer content = new StringBuffer(); content.append(id); content.append('|'); content.append(time.toString()); content.append("||"); content.append(elevation); content.append('|'); SimpleFeature f = DataUtilities.createFeature(type, content.toString()); coll.add(f); org.geotools.data.Transaction tx = fs.getTransaction(); fs.addFeatures(coll); tx.commit(); }
protected void addFeature(int id, Date time, Double elevation) throws IOException { FeatureTypeInfo timeWithStartEnd = getCatalog().getFeatureTypeByName(ELEVATION_WITH_START_END.getLocalPart()); FeatureStore fs = (FeatureStore) timeWithStartEnd.getFeatureSource(null, null); SimpleFeatureType type = (SimpleFeatureType) timeWithStartEnd.getFeatureType(); MemoryFeatureCollection coll = new MemoryFeatureCollection(type); StringBuffer content = new StringBuffer(); content.append(id); content.append('|'); content.append(time.toString()); content.append("||"); content.append(elevation); content.append('|'); SimpleFeature f = DataUtilities.createFeature(type, content.toString()); coll.add(f); org.geotools.data.Transaction tx = fs.getTransaction(); fs.addFeatures(coll); tx.commit(); }
protected void setUp() throws Exception { super.setUp(); roads = new MemoryFeatureCollection(roadType); roads.addAll(Arrays.asList(roadFeatures)); }
private MappingFeatureSource buildMappingFeatureSource( Object feature, List<SimpleFeature> features) throws IOException { MappingFeatureSource originalFeatureSource = (MappingFeatureSource) getMappingSource(feature); FeatureTypeMapping mapping = originalFeatureSource.getMapping(); AppSchemaDataAccess dataAccess = (AppSchemaDataAccess) originalFeatureSource.getDataStore(); MemoryFeatureCollection collection = new MemoryFeatureCollection(null); collection.addAll(features); MongoStaticFeatureSource staticSource = new MongoStaticFeatureSource(collection, mapping.getSource()); FeatureTypeMapping staticMapping = new FeatureTypeMapping( staticSource, mapping.getTargetFeature(), mapping.getDefaultGeometryXPath(), mapping.getAttributeMappings(), mapping.getNamespaces(), mapping.isDenormalised()); return new MappingFeatureSource(dataAccess, staticMapping); }