|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Represents a collection of features.
Implementations (and client code) should adhere to the rules set forth by java.util.Collection. That is, some methods are optional to implement, and may throw an UnsupportedOperationException.
FeatureCollection house rules:
We have also adopted an additional constraint on the use of iterator. You must call FeatureCollection.close( iterator ) to allow FeatureCollection to clean up any operating system resources used to acces information.
Example (safe) use:
Iterator iterator = collection.iterator();
try {
for( Iterator i=collection.iterator(); i.hasNext();){
Feature feature = (Feature) i.hasNext();
System.out.println( feature.getID() );
}
}
finally {
collection.close( iterator );
}
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.
Many users will be treating this as a straight forward Collection, there code will break often enough due to latency - try and close up resources for them when you can detect that an Iterator is not useful anymore.
Collections are used in two fashions, basically as you see them, and also as "range" for common opperations. You can see this with List.subCollection( Filter ). Existing RnD effort is going towards supporting this kind of use at the FeatureCollection level.
java.util.Collection, org.geotools.Feature
Nested Class Summary |
Nested classes inherited from class org.geotools.feature.Feature |
Feature.NULL |
Method Summary | |
void |
accepts(FeatureVisitor visitor,
ProgressListener progress)
Will visit the contents of the feature collection. |
void |
addListener(CollectionListener listener)
Adds a listener for collection events. |
void |
close(FeatureIterator close)
Clean up any resources assocaited with this iterator in a manner similar to JDO collections. |
void |
close(java.util.Iterator close)
Clean up after any resources assocaited with this itterator in a manner similar to JDO collections. |
FeatureIterator |
features()
Obtain a FeatureIterator of the Features within this collection. |
FeatureType |
getFeatureType()
Gets a reference to the type of this feature collection. |
FeatureType |
getSchema()
The schema for the child features of this collection. |
void |
removeListener(CollectionListener listener)
Removes a listener for collection events. |
FeatureList |
sort(SortBy order)
collection.subCollection( myFilter ).sort( {"foo","bar"} ); collection.subCollection( myFilter ).sort( "bar" ).sort("foo") |
FeatureCollection |
subCollection(Filter filter)
FeatureCollection "view" indicated by provided filter. |
Methods inherited from interface org.geotools.data.collection.ResourceCollection |
iterator, purge |
Methods inherited from interface java.util.Collection |
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, size, toArray, toArray |
Methods inherited from interface org.geotools.data.FeatureResults |
collection, getBounds, getCount, reader |
Methods inherited from interface org.geotools.feature.Feature |
getAttribute, getAttribute, getAttributes, getBounds, getDefaultGeometry, getID, getNumberOfAttributes, getParent, setAttribute, setAttribute, setDefaultGeometry, setParent |
Method Detail |
public FeatureIterator features()
The implementation of Collection must adhere to the rules of
fail-fast concurrent modification. In addition (to allow for
resource backed collections, the close( Iterator )
method must be called.
This is almost equivalent to:
getAttribute(getFeatureType().getAttributeType(0).getName()).iterator();
.
Iterator<Feature>
FeatureIterator iterator=collection.features();
try {
while( iterator.hasNext() ){
Feature feature = iterator.next();
System.out.println( feature.getID() );
}
}
finally {
collection.close( iterator );
}
GML Note: The contents of this iterator are considered to be defined by featureMember tags (and/or the single allowed FeatureMembers tag). Please see getFeatureType for more details.
public void close(FeatureIterator close)
You must be sure to allow null values, this is because in a try/finally block client code may not be sure if they have actualy succeed in assign a value to an iterator they wish to ensure is closed. By permiting null as an api we prevent a null check in lots of finally statements.
Note: Because of FeatureReader using an interator internally, there is only one implementation of this method that makes any sense:
public void close( FeatureIterator iterator) {
if( iterator != null ) iterator.close();
}
public void close(java.util.Iterator close)
Iterator iterator = collection.iterator();
try {
for( Iterator i=collection.iterator(); i.hasNext();){
Feature feature = (Feature) i.hasNext();
System.out.println( feature.getID() );
}
}
finally {
collection.close( iterator );
}
close
in interface ResourceCollection
close
- public void addListener(CollectionListener listener) throws java.lang.NullPointerException
When this collection is backed by live data the event notification will follow the guidelines outlined by FeatureListner.
listener
- The listener to add
java.lang.NullPointerException
- If the listener is null.public void removeListener(CollectionListener listener) throws java.lang.NullPointerException
listener
- The listener to remove
java.lang.NullPointerException
- If the listener is null.public FeatureType getFeatureType()
There are several limitations on the use of FeatureType with respect to a FeatureCollection.
GML 3.x: all FeatureCollections decend from gml:AbstractFeatureCollectionType:
GML 3.x: gml:AbstractFeatureCollectionType decends from gml:BoundedFeatureType:
There is a difference between getFeatureType() and getSchema(), getSchema is named for historical reasons and reprensets the LCD FeatureType that best represents the contents of this collection.
getFeatureType
in interface Feature
public FeatureType getSchema()
There is a difference between getFeatureType() and getSchema()represents the LCD FeatureType that best represents the contents of this collection.
The method getSchema() is named for compatability with the geotools 2.0 API. In the Geotools 2.2 time frame we should be able to replace this method with a careful check of getFeatureType() and its attributes.
getSchema
in interface FeatureResults
public void accepts(FeatureVisitor visitor, ProgressListener progress) throws java.io.IOException
Note: When performing aggregate calculations please consider using the Filter/Expression/Function API as it may be optimized.
visitor
-
java.io.IOException
public FeatureCollection subCollection(Filter filter)
The contents of the returned FeatureCollection are determined by applying the provider Fitler to the entire contents of this FeatureCollection. The result is "live" and modifications will be shared.
This method is used cut down on the number of filter based methods required for a useful FeatureCollection construct. The FeatureCollections returned really should be considered as a temporary "view" used to control the range of a removeAll, or modify opperation.
Example Use:
collection.subCollection( filter ).clear();
The above recommended use is agreement with the Collections API precident of
List.subList( start, end ).
The results of subCollection:
filter
-
FeatureList
public FeatureList sort(SortBy order)
order
-
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |