|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.geotools.feature.collection.AbstractResourceCollection
org.geotools.feature.collection.SubFeatureCollection
Used as a reasonable default implementation for subCollection.
Note: to implementors, this is not optimal, please do your own thing - your users will thank you.
| Nested Class Summary |
| Nested classes inherited from class org.geotools.feature.Feature |
Feature.NULL |
| Field Summary | |
protected FeatureCollection |
collection
Origional Collection |
protected Filter |
filter
Filter |
protected FeatureState |
state
|
| Fields inherited from class org.geotools.feature.collection.AbstractResourceCollection |
open |
| Constructor Summary | |
SubFeatureCollection(FeatureCollection collection)
|
|
SubFeatureCollection(FeatureCollection collection,
Filter subfilter)
|
|
| Method Summary | |
void |
accepts(FeatureVisitor visitor,
ProgressListener progress)
Accepts a visitor, which then visits each feature in the 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 |
closeIterator(java.util.Iterator iterator)
Please override to cleanup after your own iterators, and any used resources. |
FeatureCollection |
collection()
Convert this set of results to a FeatureCollection. |
protected Filter |
createFilter()
Override to implement subsetting |
FeatureIterator |
features()
Obtain a FeatureIterator of the Features within this collection. |
protected Filter |
filter()
|
java.lang.Object |
getAttribute(int index)
Gets an attribute by the given zero-based index. |
java.lang.Object |
getAttribute(java.lang.String xPath)
Gets an attribute for this feature at the location specified by xPath. |
java.lang.Object[] |
getAttributes(java.lang.Object[] attributes)
Copy all the attributes of this Feature into the given array. |
com.vividsolutions.jts.geom.Envelope |
getBounds()
Returns the bounding box of this FeatureResults. |
int |
getCount()
Returns the number of Features in this FeatureResults. |
com.vividsolutions.jts.geom.Geometry |
getDefaultGeometry()
Gets the default geometry for this feature. |
FeatureType |
getFeatureType()
Gets a reference to the type of this feature collection. |
java.lang.String |
getID()
Gets the unique feature ID for this feature. |
int |
getNumberOfAttributes()
Get the number of attributes this feature has. |
FeatureCollection |
getParent()
Gets the feature collection this feature is stored in. |
FeatureType |
getSchema()
The schema for the child features of this collection. |
boolean |
isEmpty()
|
java.util.Iterator |
openIterator()
Open a resource based Iterator, we will call close( iterator ). |
void |
purge()
Close any outstanding resources released by this resources. |
FeatureReader |
reader()
Provides access to the Features, please note that FeatureReader is a blocking api. |
void |
removeListener(CollectionListener listener)
Removes a listener for collection events. |
void |
setAttribute(int position,
java.lang.Object val)
Sets an attribute by the given zero-based index. |
void |
setAttribute(java.lang.String xPath,
java.lang.Object attribute)
Sets a single attribute for this feature, passed as a complex object. |
void |
setDefaultGeometry(com.vividsolutions.jts.geom.Geometry g)
Sets the default geometry for this feature. |
void |
setParent(FeatureCollection collection)
Sets the parent collection this feature is stored in, if it is not already set. |
int |
size()
Returns the number of elements in this collection. |
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 class org.geotools.feature.collection.AbstractResourceCollection |
add, addAll, clear, close, contains, containsAll, iterator, remove, removeAll, retainAll, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.geotools.feature.FeatureCollection |
close |
| Methods inherited from interface org.geotools.data.collection.ResourceCollection |
iterator |
| Methods inherited from interface java.util.Collection |
add, addAll, clear, contains, containsAll, equals, hashCode, remove, removeAll, retainAll, toArray, toArray |
| Field Detail |
protected Filter filter
protected FeatureCollection collection
protected FeatureState state
| Constructor Detail |
public SubFeatureCollection(FeatureCollection collection)
public SubFeatureCollection(FeatureCollection collection,
Filter subfilter)
| Method Detail |
protected Filter filter()
protected Filter createFilter()
public FeatureType getFeatureType()
FeatureCollectionThere 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 FeatureCollectionpublic FeatureIterator features()
FeatureCollection
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.
features in interface FeatureCollectionpublic void closeIterator(java.util.Iterator iterator)
AbstractResourceCollectionAs an example if the iterator was working off a File then the inputstream should be closed.
Subclass must call super.close( close ) to allow the list of open iterators to be adjusted.
closeIterator in class AbstractResourceCollectioniterator - Iterator, will not be nullpublic void close(FeatureIterator close)
FeatureCollectionYou 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();
}
close in interface FeatureCollectionpublic java.lang.String getID()
Feature
getID in interface Featurepublic com.vividsolutions.jts.geom.Envelope getBounds()
FeatureResults
This opperation may be expensive. Consider
FeatureSource.getBounds( Query ) as an alternative.
public Envelope getBounds() throws IOException {
Envelope newBBox = new Envelope();
Envelope internal;
Feature feature;
for (FeatureReader r = reader(); r.hasNext();) {
feature = r.next();
internal = feature.getDefaultGeometry().getEnvelopeInternal();
newBBox.expandToInclude(internal);
}
return newBBox;
}
getBounds in interface FeatureResultspublic com.vividsolutions.jts.geom.Geometry getDefaultGeometry()
Feature
This method will return null if no DefaultGeometry has been
defined by the schema.
getDefaultGeometry in interface Featurenull
public void setDefaultGeometry(com.vividsolutions.jts.geom.Geometry g)
throws IllegalAttributeException
Feature
setDefaultGeometry in interface Featureg - The geometry to set.
IllegalAttributeException - If the AttributeType is not a
geometry, or is invalid for some other reason.
public void addListener(CollectionListener listener)
throws java.lang.NullPointerException
FeatureCollectionWhen this collection is backed by live data the event notification will follow the guidelines outlined by FeatureListner.
addListener in interface FeatureCollectionlistener - The listener to add
java.lang.NullPointerException - If the listener is null.
public void removeListener(CollectionListener listener)
throws java.lang.NullPointerException
FeatureCollection
removeListener in interface FeatureCollectionlistener - The listener to remove
java.lang.NullPointerException - If the listener is null.public FeatureCollection getParent()
Feature
getParent in interface Featurepublic void setParent(FeatureCollection collection)
Feature
setParent in interface Featurecollection - the collection to be set as parent.public java.lang.Object[] getAttributes(java.lang.Object[] attributes)
Feature
getAttributes in interface Featureattributes - An array to copy attributes into. May be null.
public java.lang.Object getAttribute(java.lang.String xPath)
Feature
getAttribute in interface FeaturexPath - XPath representation of attribute location.
public java.lang.Object getAttribute(int index)
Feature
getAttribute in interface Featureindex - The requested index. Must be 0 <= idx <
getNumberOfAttributes().
Feature.getAttribute(String)
public void setAttribute(int position,
java.lang.Object val)
throws IllegalAttributeException,
java.lang.ArrayIndexOutOfBoundsException
Feature
setAttribute in interface Featureposition - The requested index. Must be 0 <= idx <
getNumberOfAttributes()val - An object representing the attribute being set
java.lang.ArrayIndexOutOfBoundsException - if an invalid position is given
IllegalAttributeException - if the passed in val does not validate
against the AttributeType at that position.Feature.setAttribute(String, Object)public int getNumberOfAttributes()
Feature
getNumberOfAttributes in interface Feature
public void setAttribute(java.lang.String xPath,
java.lang.Object attribute)
throws IllegalAttributeException
Feature
setAttribute in interface FeaturexPath - XPath representation of attribute location.attribute - Feature attribute to set.
IllegalAttributeException - If the attribute is illegal for the
path specified.public FeatureCollection subCollection(Filter filter)
FeatureCollectionThe 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:
subCollection in interface FeatureCollectionfilter -
FeatureListpublic int size()
AbstractResourceCollection
size in interface java.util.Collectionsize in class AbstractResourceCollectionpublic boolean isEmpty()
isEmpty in interface java.util.CollectionisEmpty in class AbstractResourceCollectionpublic java.util.Iterator openIterator()
AbstractResourceCollection
Please subclass to provide your own iterator for the the ResourceCollection,
note iterator() is implemented to call open()
and track the results in for later purge().
openIterator in class AbstractResourceCollectionpublic FeatureType getSchema()
FeatureCollectionThere 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 FeatureCollection
public void accepts(FeatureVisitor visitor,
ProgressListener progress)
throws java.io.IOException
accepts in interface FeatureCollectionvisitor -
java.io.IOException
public FeatureReader reader()
throws java.io.IOException
FeatureResults
reader in interface FeatureResultsjava.io.IOException - DOCUMENT ME!
public int getCount()
throws java.io.IOException
FeatureResults
This opperation may be expensive. Consider FeatureSource.getCount(
Query ) as an alternative.
public int getCount() throws IOException {
int count = 0;
for (FeatureReader r = reader(); r.hasNext(); count++) {
r.next();
}
return count;
}
getCount in interface FeatureResultsjava.io.IOException - If there are problems getting the count
public FeatureCollection collection()
throws java.io.IOException
FeatureResultsThis method is logically the same as:
public FeatureCollection collection() throws IOException {
FeatureCollection collection = FeatureCollections.newCollection()
for (FeatureReader r = reader(); r.hasNext();) {
collection.add( r.next() );
}
return collection;
}
collection in interface FeatureResultsjava.io.IOException - If any problems occur aquiring Featurespublic FeatureList sort(SortBy order)
FeatureCollection
sort in interface FeatureCollectionorder -
public void purge()
ResourceCollectionThis method should be used with great caution, it is however available to allow the use of the ResourceCollection with algorthims that are unaware of the need to close iterators after use.
Example of using a normal Collections utility method:
Collections.sort( collection );
collection.purge();
purge in interface ResourceCollectionpurge in class AbstractResourceCollection
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||