Collection of features, often handled as a result set.
Where possible FeatureCollection is method compatible with {@link Collection}.
SimpleFeatureCollection house rules:
- Each iterator is considered a live connection which must be closed (see example below)
- Features are not specifically ordered within the SimpleFeatureCollection
- Two Feature instances cannot exist with the same {@link FeatureId}
FeatureIterator close
FeatureCollection provides streaming access with the following restriction on the use of {@link FeatureIterator}: You must call {@link FeatureIterator#close()}. This allows FeatureCollection to clean up any operating system resources used to access information.
Example (safe) use:
FeatureIterator iterator = featureCollection.features(); try { while( iterator.hasNext() ){ Feature feature = iterator.next(); System.out.println( feature.getID() ); } } finally { iterator.close(); }
And in Java 7:
try ( FeatureIterator iterator = featureCollection.features() ){ while( iterator.hasNext() ){ Feature feature = iterator.next(); System.out.println( feature.getID() ); } }
Handy Tip: Although many resource backed collections will choose to release resources at when the iterator has reached the end of its contents this is not something you should rely on.
FeatureCollection Implementation Tips
Auto close: Try and close up resources when you can detect that an Iterator is no longer in use.
Lazy Connect: FeatureCollection is used in two fashions, as a result set, where each iterator acts as a cursor over the content. Also as a predefined query which can be refined further. An example is using featureCollection.subCollection( Filter ) or featureCollection.sort( SortBy ) before listing features out of a FeatureCollection.
@see org.geotools.Feature
@author Ian Turton, CCG
@author Rob Hranac, VFNY
@author Ian Schneider, USDA-ARS
@author Jody Garnett, LISAsoft
@source $URL$
@version $Id$