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());
SimpleFeatureIterator it = featureCollection.features(); SimpleFeature protoFt = it.next(); if (propertyFields == null) { propertyFields = new ArrayList<String>(); it = featureCollection.features(); while (it.hasNext()) { SimpleFeature feature = it.next(); Geometry geom = (Geometry) feature.getDefaultGeometry();
/** Helper method that crestes a lsit of features from a collection (iterator) of features. */ private List<SimpleFeature> getFeatures(SimpleFeatureCollection collection) { List<SimpleFeature> features = new ArrayList<>(); try (SimpleFeatureIterator iterator = collection.features()) { while (iterator.hasNext()) { features.add(iterator.next()); } } return features; }
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(); } }
private void assertSortedOnPeopleAsc(SimpleFeatureIterator fi) throws IllegalArgumentException, NoSuchElementException, IOException { double prev = -1; while (fi.hasNext()) { SimpleFeature f = fi.next(); int curr = (Integer) f.getAttribute("PERSONS"); if (prev > 0) { assertTrue(curr >= prev); } prev = curr; } } }
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(); } }
@Override public void addGranules(SimpleFeatureCollection granules) { checkTransaction(); SimpleFeatureIterator features = granules.features(); boolean firstSchemaCompatibilityCheck = false; while (features.hasNext()) { SimpleFeature feature = features.next(); if (!firstSchemaCompatibilityCheck) { firstSchemaCompatibilityCheck = true; checkSchemaCompatibility(feature); } try { catalog.addGranule(typeName, feature, transaction); } catch (IOException e) { throw new RuntimeException( "Exception occurred while adding granules to the catalog", e); } } }
@Test public void iterator() { createPointFeaturesAtCorners(WORLD); SimpleFeatureIterator iter = featureCollection.features(); assertNotNull(iter); assertTrue(iter.hasNext()); List<SimpleFeature> copy = new ArrayList<SimpleFeature>(featureList); while (iter.hasNext()) { SimpleFeature f = iter.next(); assertTrue(copy.remove(f)); } assertTrue(copy.isEmpty()); }
/** * 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(); } }
protected Set<String> collectFeatureIds(SimpleFeatureCollection fc) { Set<String> identifiers = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); try (SimpleFeatureIterator fi = fc.features()) { while (fi.hasNext()) { SimpleFeature sf = fi.next(); identifiers.add(sf.getID()); } } return identifiers; } }
public void testNaturalSortingAsc() throws Exception { Query q = new Query(featureSource.getSchema().getTypeName()); q.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER}); try (SimpleFeatureIterator features = featureSource.getFeatures(q).features()) { String prevId = null; while (features.hasNext()) { String currId = features.next().getID(); if (prevId != null) assertTrue(prevId.compareTo(currId) <= 0); prevId = currId; } } }
/** * 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(); } }
private void count(SimpleFeatureStore store, int expected) throws IOException, IllegalAttributeException { int i = 0; for (SimpleFeatureIterator reader = store.getFeatures().features(); reader.hasNext(); ) { reader.next(); i++; } assertEquals("Number of known feature as obtained from reader", expected, i); } }