org.geotools.feature
Class DefaultFeature

Object
  extended by SimpleFeatureImpl
      extended by DefaultFeature
All Implemented Interfaces:
Cloneable, Attribute, ComplexAttribute, Feature, Property, SimpleFeature

public class DefaultFeature
extends SimpleFeatureImpl
implements SimpleFeature, Cloneable

Provides a more efficient feature representation for the flat and complex features. This implementation actually not only enforces feature type synchronization, it also enforces the use of its accessor methods to change the state of internal object representations. In this case, the implementation is trivial, since all allowed attribute objects (from the feature type) are immutable.

Author:
Chris Holmes, TOPP
, Rob Hranac, TOPP, Ian Schneider ARS-USDA
Module:
TODO:
TODO: look at synchronization (or locks as IanS thinks), REVISIT: Right now we always validate, which means whenever a Feature is created or a new value set then an operation must be performed. One thing we should consider is to allow a Feature to turn off its its validation - which would likely improve performance with large datasets. If you are reading from a database, with a FeatureType you got from the database, it is probably a reasonable assumption that the Features contained in it will properly validate. I am not sure if this should with a switch in DefaultFeature, or perhaps an interface that says if it is validating or not, or maybe even an option in Feature. But it would be a nice option to have - if datastore implementors could at least create their features without validating (though probably should return Features that will check for validity if someone else tries to change them).

Nested Class Summary
 
Nested classes/interfaces inherited from interface Feature
Feature.NULL
 
Field Summary
 
Fields inherited from class SimpleFeatureImpl
attributeUserData, featureType, id, index, userData, validating, values
 
Constructor Summary
protected DefaultFeature(DefaultFeatureType schema, Object[] attributes)
          Creates a new instance of flat feature, which must take a flat feature type schema and all attributes as arguments.
protected DefaultFeature(DefaultFeatureType schema, Object[] attributes, String featureID)
          Creates a new instance of flat feature, which must take a flat feature type schema and all attributes as arguments.
  DefaultFeature(List attributes, DefaultFeatureType schema, String id)
           
 
Method Summary
 Object clone()
          Creates an exact copy of this feature.
 boolean equals(Object obj)
          override of equals.
 Object[] getAttributes(Object[] array)
          Copy all the attributes of this Feature into the given array.
 ReferencedEnvelope getBounds()
          Get the total bounds of this feature which is calculated by doing a union of the bounds of each geometry this feature is associated with.
 Geometry getDefaultGeometry()
          Deprecated. use getDefaultGeometry().
 FeatureType getFeatureType()
          Gets a reference to the feature type schema for this feature.
 int getNumberOfAttributes()
          Get the number of attributes this feature has.
 FeatureCollection<SimpleFeatureType,SimpleFeature> getParent()
          Gets the feature collection this feature is stored in.
 void setAttribute(int position, Object val)
          Sets the attribute at position to val.
 void setAttribute(String xPath, Object attribute)
          Sets a single attribute for this feature, passed as a complex object.
 void setAttributes(Object[] attributes)
          Sets all attributes for this feature, passed as an array.
 void setDefaultGeometry(Geometry geometry)
          Deprecated. use setDefaultGeometry(Geometry).
 void setParent(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
          Sets the parent collection this feature is stored in, if it is not already set.
 Feature toComplex()
           
 String toString()
          Returns a string representation of this feature.
 
Methods inherited from class SimpleFeatureImpl
getAttribute, getAttribute, getAttribute, getAttributeCount, getAttributes, getDefaultGeometryProperty, getDescriptor, getID, getIdentifier, getName, getProperties, getProperties, getProperties, getProperty, getProperty, getType, getUserData, getValue, hashCode, isNillable, setAttribute, setAttributes, setDefaultGeometry, setDefaultGeometryProperty, setValue, setValue, validate
 
Methods inherited from class Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface SimpleFeature
getAttribute, getAttribute
 
Methods inherited from interface Feature
getID
 
Methods inherited from interface SimpleFeature
getAttribute, getAttributeCount, getAttributes, getType, setAttribute, setAttributes, setDefaultGeometry
 
Methods inherited from interface Feature
getDefaultGeometryProperty, getIdentifier, setDefaultGeometryProperty
 
Methods inherited from interface ComplexAttribute
getProperties, getProperties, getProperties, getProperty, getProperty, getValue, setValue, validate
 
Methods inherited from interface Attribute
getDescriptor
 
Methods inherited from interface Property
getName, getUserData, isNillable, setValue
 

Constructor Detail

DefaultFeature

protected DefaultFeature(DefaultFeatureType schema,
                         Object[] attributes,
                         String featureID)
                  throws IllegalAttributeException,
                         NullPointerException
Creates a new instance of flat feature, which must take a flat feature type schema and all attributes as arguments.

Parameters:
schema - Feature type schema for this flat feature.
attributes - Initial attributes for this feature.
featureID - The unique ID for this feature.
Throws:
IllegalAttributeException - Attribtues do not conform to feature type schema.
NullPointerException - if schema is null.

DefaultFeature

protected DefaultFeature(DefaultFeatureType schema,
                         Object[] attributes)
                  throws IllegalAttributeException
Creates a new instance of flat feature, which must take a flat feature type schema and all attributes as arguments.

Parameters:
schema - Feature type schema for this flat feature.
attributes - Initial attributes for this feature.
Throws:
IllegalAttributeException - Attribtues do not conform to feature type schema.
TODO:
REVISIT: should we allow this? Force users to explicitly set featureID to null?

DefaultFeature

public DefaultFeature(List attributes,
                      DefaultFeatureType schema,
                      String id)
Method Detail

getFeatureType

public FeatureType getFeatureType()
Gets a reference to the feature type schema for this feature.

Specified by:
getFeatureType in interface SimpleFeature
Overrides:
getFeatureType in class SimpleFeatureImpl
Returns:
A copy of this feature's metadata in the form of a feature type schema.

getAttributes

public Object[] getAttributes(Object[] array)
Copy all the attributes of this Feature into the given array. If the argument array is null, a new one will be created. Gets all attributes from this feature, returned as a complex object array. This array comes with no metadata, so to interpret this collection the caller class should ask for the schema as well.

Parameters:
array - The array to copy the attributes into.
Returns:
The array passed in, or a new one if null.

setAttribute

public void setAttribute(int position,
                         Object val)
Sets the attribute at position to val.

Specified by:
setAttribute in interface SimpleFeature
Overrides:
setAttribute in class SimpleFeatureImpl
Parameters:
position - the index of the attribute to set.
val - the new value to give the attribute at position.
Throws:
IllegalAttributeException - if the passed in val does not validate against the AttributeType at that position.

setAttributes

public void setAttributes(Object[] attributes)
                   throws IllegalAttributeException
Sets all attributes for this feature, passed as an array. All attributes are checked for validity before adding.

Specified by:
setAttributes in interface SimpleFeature
Overrides:
setAttributes in class SimpleFeatureImpl
Parameters:
attributes - All feature attributes.
Throws:
IllegalAttributeException - Passed attributes do not match feature type.

setAttribute

public void setAttribute(String xPath,
                         Object attribute)
                  throws IllegalAttributeException
Sets a single attribute for this feature, passed as a complex object. If the attribute does not exist or the object does not conform to the internal feature type, an exception is thrown.

Specified by:
setAttribute in interface SimpleFeature
Overrides:
setAttribute in class SimpleFeatureImpl
Parameters:
xPath - XPath representation of attribute location.
attribute - Feature attribute to set.
Throws:
IllegalAttributeException - Passed attribute does not match feature type

getDefaultGeometry

public Geometry getDefaultGeometry()
Deprecated. use getDefaultGeometry().

Gets the geometry for this feature.

Specified by:
getDefaultGeometry in interface SimpleFeature
Overrides:
getDefaultGeometry in class SimpleFeatureImpl
Returns:
Geometry for this feature.

setDefaultGeometry

public void setDefaultGeometry(Geometry geometry)
                        throws IllegalAttributeException
Deprecated. use setDefaultGeometry(Geometry).

Modifies the geometry.

Parameters:
geometry - All feature attributes.
Throws:
IllegalAttributeException - if the feature does not have a geometry.

getNumberOfAttributes

public int getNumberOfAttributes()
Get the number of attributes this feature has. This is simply a convenience method for calling getFeatureType().getNumberOfAttributes();

Overrides:
getNumberOfAttributes in class SimpleFeatureImpl
Returns:
The total number of attributes this Feature contains.

getBounds

public ReferencedEnvelope getBounds()
Get the total bounds of this feature which is calculated by doing a union of the bounds of each geometry this feature is associated with.

Specified by:
getBounds in interface Feature
Overrides:
getBounds in class SimpleFeatureImpl
Returns:
An Envelope containing the total bounds of this Feature.
TODO:
REVISIT: what to return if there are no geometries in the feature? For now we'll return a null envelope, make this part of interface? (IanS - by OGC standards, all Feature must have geom)

clone

public Object clone()
Creates an exact copy of this feature.

Overrides:
clone in class Object
Returns:
A default feature.
Throws:
RuntimeException - DOCUMENT ME!

toString

public String toString()
Returns a string representation of this feature.

Overrides:
toString in class Object
Returns:
A representation of this feature as a string.

equals

public boolean equals(Object obj)
override of equals. Returns if the passed in object is equal to this.

Overrides:
equals in class SimpleFeatureImpl
Parameters:
obj - the Object to test for equality.
Returns:
true if the object is equal, false otherwise.

getParent

public FeatureCollection<SimpleFeatureType,SimpleFeature> getParent()
Gets the feature collection this feature is stored in.

Returns:
the collection that is the parent of this feature.

setParent

public void setParent(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
Sets the parent collection this feature is stored in, if it is not already set. If it is set then this method does nothing.

Parameters:
collection - the collection to be set as parent.

toComplex

public Feature toComplex()


Copyright © 1996-2009 Geotools. All Rights Reserved.