SimpleFeatureCollection featureCollection = featureSource.getFeatures(query); SimpleFeatureIterator it = featureCollection.features(); int i = 0; while (it.hasNext()) { SimpleFeature feature = it.next(); Geometry geom = (Geometry) feature.getDefaultGeometry(); Point point = null; it.close(); } catch (Exception ex) { LOG.error("Error loading population from shapefile: {}", ex.getMessage());
@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()); }
public ReferencedEnvelope getBounds() { ReferencedEnvelope bounds = null; SimpleFeatureIterator i = features(); try { if (!i.hasNext()) { bounds = new ReferencedEnvelope(); bounds.setToNull(); } else { SimpleFeature first = (SimpleFeature) i.next(); bounds = new ReferencedEnvelope(first.getBounds()); } while (i.hasNext()) { SimpleFeature f = (SimpleFeature) i.next(); bounds.include(f.getBounds()); } return bounds; } finally { i.close(); } }
public void testFeatureMembers() throws Exception { Element featureCollection = GML3MockData.element(TEST.TestFeatureCollection, document, document); Element featureMember = GML3MockData.element(GML.featureMembers, document, featureCollection); Element feature = GML3MockData.feature(document, featureMember); feature.setAttributeNS(GML.NAMESPACE, "id", "fid.1"); feature = GML3MockData.feature(document, featureMember); feature.setAttributeNS(GML.NAMESPACE, "id", "fid.2"); SimpleFeatureCollection fc = (SimpleFeatureCollection) parse(); assertNotNull(fc); assertEquals(2, fc.size()); SimpleFeatureIterator i = fc.features(); try { SimpleFeature f = (SimpleFeature) i.next(); assertEquals("fid.1", f.getID()); f = (SimpleFeature) i.next(); assertEquals("fid.2", f.getID()); } finally { i.close(); } } }
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) { } }
static void accept(SimpleFeatureCollection collection, FeatureVisitor[] visitors) { SimpleFeatureIterator iterator = collection.features(); try { while (iterator.hasNext()) { SimpleFeature feature = (SimpleFeature) iterator.next(); for (int i = 0; i < visitors.length; i++) { FeatureVisitor visitor = visitors[i]; visitor.visit(feature); } } } finally { iterator.close(); } }
public void testFeatureMember() throws Exception { Element featureCollection = GML3MockData.element(TEST.TestFeatureCollection, document, document); Element featureMember = GML3MockData.element(GML.featureMember, document, featureCollection); Element feature = GML3MockData.feature(document, featureMember); feature.setAttributeNS(GML.NAMESPACE, "id", "fid.1"); featureMember = GML3MockData.element(GML.featureMember, document, featureCollection); feature = GML3MockData.feature(document, featureMember); feature.setAttributeNS(GML.NAMESPACE, "id", "fid.2"); SimpleFeatureCollection fc = (SimpleFeatureCollection) parse(); assertNotNull(fc); assertEquals(2, fc.size()); SimpleFeatureIterator i = fc.features(); try { SimpleFeature f = (SimpleFeature) i.next(); assertEquals("fid.1", f.getID()); f = (SimpleFeature) i.next(); assertEquals("fid.2", f.getID()); } finally { i.close(); } }
/** * Navigate the collection and call vistor.visit( Feature ) for each element in the collection. * * @param collection the SimpleFeatureCollection containing the features we want to visit * @param visitor the visitor which already knows which attributes it wants to meet */ static void accept(SimpleFeatureCollection collection, FeatureVisitor visitor) { SimpleFeatureIterator iterator = collection.features(); try { while (iterator.hasNext()) { SimpleFeature feature = (SimpleFeature) iterator.next(); visitor.visit(feature); } } finally { iterator.close(); } }
/** * item at the specified index. * * @param index index of item * @return the item at the specified index. * @throws IndexOutOfBoundsException if index is not between 0 and size */ public SimpleFeature get(int position) { FeatureId fid = index.get(position); if (collection instanceof RandomFeatureAccess) { RandomFeatureAccess random = (RandomFeatureAccess) collection; return random.getFeatureMember(fid.getID()); } SimpleFeatureIterator it = collection.features(); try { while (it.hasNext()) { SimpleFeature feature = (SimpleFeature) it.next(); if (id.equals(feature.getID())) { return feature; } } throw new IndexOutOfBoundsException(); } finally { it.close(); } }
SimpleFeatureIterator it = collection.features(); try { while (it.hasNext()) { SimpleFeature feature = it.next(); featureCache.put(id, feature); if (id.equals(feature.getID())) { it.close(); } else { SimpleFeatureIterator it = collection.features(); try { while (it.hasNext()) { SimpleFeature feature = it.next(); if (id.equals(feature.getID())) { return feature; it.close();