org.opengis.feature.simple
Interface SimpleFeature

All Superinterfaces:
Attribute, ComplexAttribute, Feature, Property
All Known Implementing Classes:
DecoratingFeature, JDBCFeatureReader.ResultSetFeature, LenientFeature, PreGeneralizedSimpleFeature, SimpleFeatureImpl

public interface SimpleFeature
extends Feature

An instance of SimpleFeatureType composed of fixed list values in a known order.

The definition of a "simple feature" can be summed up as the following:

Attribute Access

The order and multiplicity restrictions on simple feature make attribute values accessible via an index. For example consider the following shapefile entry:
  | GEOMETRY   | INT | STRING |
  | POINT(0 0) |  0  | "zero" |
  
Accessing attributes via index would look like:
  SimpleFeature feature = ...;

  Geometry g = (Geometry) feature.getAttribute( 0 );
  Integer i = (Integer) feature.getAttribute( 1 );
  String s = (String) feature.getAttribute( 2 );
  
One could also access by name:
  SimpleFeature feature = ...;

  Geometry g = (Geometry) feature.getAttribute( "GEOMETRY" );
  Integer i = (Integer) feature.getAttribute( "INT" );
  String s = (String) feature.getAttribute( "STRING" );
  

Note: Attribute access via getAttribute() methods returns attribute values, and not the attributes themselves. For access to the actual attributes ComplexAttribute.getProperty(String) can be used.

Since:
2.5
Author:
Jody Garnett (LISAsoft), Justin Deoliveira (The Open Planning Project)
See Also:
SimpleFeatureType

Method Summary
 Object getAttribute(int index)
          Gets an attribute value by index.
 Object getAttribute(Name name)
          Gets an attribute value by name.
 Object getAttribute(String name)
          Gets an attribute value by name.
 int getAttributeCount()
          The number of attributes the feature is composed of.
 List<Object> getAttributes()
          Returns a list of the values of the attributes contained by the feature.
 Object getDefaultGeometry()
          Returns the value of the default geometry of the feature.
 SimpleFeatureType getFeatureType()
          The type of the feature.
 String getID()
          Unique Identifier for the SimpleFeature This value is non-null and should be the same as getIdentifier().toString().
 SimpleFeatureType getType()
          Override and type narrow to SimpleFeatureType.
 void setAttribute(int index, Object value)
          Sets an attribute value by index.
 void setAttribute(Name name, Object value)
          Sets an attribute value by name.
 void setAttribute(String name, Object value)
          Sets an attribute value by name.
 void setAttributes(List<Object> values)
          Sets the values of the attributes contained by the feature.
 void setAttributes(Object[] values)
          Sets the values of the attributes contained by the feature.
 void setDefaultGeometry(Object geometry)
          Sets the value of the default geometry for the feature.
 
Methods inherited from interface Feature
getBounds, 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
 

Method Detail

getID

String getID()
Unique Identifier for the SimpleFeature

This value is non-null and should be the same as getIdentifier().toString(). Please note that an ID may be provided

Returns:
A unique identifier for the attribute, or null if the attribute is non-identifiable.

getType

SimpleFeatureType getType()
Override and type narrow to SimpleFeatureType.

Specified by:
getType in interface Attribute
Specified by:
getType in interface ComplexAttribute
Specified by:
getType in interface Feature
Specified by:
getType in interface Property
Returns:
The feature type
See Also:
Attribute.getType()

getFeatureType

SimpleFeatureType getFeatureType()
The type of the feature.

This method is a synonym for getType().

See Also:
getType()

getAttributes

List<Object> getAttributes()
Returns a list of the values of the attributes contained by the feature.

This method is a convenience for:

 List values = new ArrayList();
 for ( Property p : getProperties(); ) {
   values.add( p.getValue() );
 }

 return values;
 

Returns:
List of attribute values for the feature.

setAttributes

void setAttributes(List<Object> values)
Sets the values of the attributes contained by the feature.

The values must be in the order of the attributes defined by the feature type.

This method is a convenience for:

 int i = 0;
 for ( Property p : getProperties() ) {
   p.setValue( values.get( i++ ) );
 }
 

Parameters:
values - The attribute values to set.

setAttributes

void setAttributes(Object[] values)
Sets the values of the attributes contained by the feature.

The values must be in the order of the attributes defined by the feature type.

This method is a convenience for:

 for ( Property p : getProperties() ) {
   p.setValue( values[i] );
 }
 

Parameters:
values - The attribute values to set.

getAttribute

Object getAttribute(String name)
Gets an attribute value by name.

This method is a convenience for:

 Property p = getProperty( name );
 return p.getValue();
 

Parameters:
name - The name of the attribute whose value to retrieve.
Returns:
The attribute value, or null if no such attribute exists with the specified name.

setAttribute

void setAttribute(String name,
                  Object value)
Sets an attribute value by name.

This method is a convenience for:

 Property p = getProperty( name );
 p.setValue(value);
 

Parameters:
name - The name of the attribute whose value to set.
value - The new value of the attribute.

getAttribute

Object getAttribute(Name name)
Gets an attribute value by name.

This method is a convenience for:

 Property p = getProperty( name );
 return p.getValue();
 

Since attribute names in simple features do not have a namespace uri this method is equivalent to calling getAttribute(name.getLocalPart()).

Parameters:
name - The name of the attribute whose value to retrieve.
Returns:
The attribute value, or null if no such attribute exists with the specified name.

setAttribute

void setAttribute(Name name,
                  Object value)
Sets an attribute value by name.

This method is a convenience for:

 Property p = getProperty( name );
 p.setValue(value);
 

Since attribute names in simple features do not have a namespace uri this method is equivalent to calling setAttribute(name.getLocalPart(), value).

Parameters:
name - The name of the attribute whose value to set.
value - The new value of the attribute.

getAttribute

Object getAttribute(int index)
                    throws IndexOutOfBoundsException
Gets an attribute value by index.

This method is a convenience for:

 Property p = ((List)getProperties()).get( i ) ;
 return p.getValue();
 

Parameters:
index - The index of the attribute whose value to get.
Returns:
The attribute value at the specified index.
Throws:
IndexOutOfBoundsException - If the specified index is out of bounds.

setAttribute

void setAttribute(int index,
                  Object value)
                  throws IndexOutOfBoundsException
Sets an attribute value by index.

This method is a convenience for:

 Property p = ((List)getProperties()).get( i ) ;
 p.setValue(value);
 

Parameters:
index - The index of the attribute whose value to set.
value - The new value of the attribute.
Throws:
IndexOutOfBoundsException - If the specified index is out of bounds.

getAttributeCount

int getAttributeCount()
The number of attributes the feature is composed of.

This is a convenience for:

   return getAttributes().size();
 

Returns:
Number of attributes of the feature.

getDefaultGeometry

Object getDefaultGeometry()
Returns the value of the default geometry of the feature.

This method is convenience for:

 return getDefaultGeometry().getValue();
 

Returns:
The default geometry, or null if no default geometry attribute exists.

setDefaultGeometry

void setDefaultGeometry(Object geometry)
Sets the value of the default geometry for the feature.

This method is convenience for:

 getDefaultGeometry().setValue(geometry);
 

Parameters:
geometry - The new default geometry value.


Copyright © 1996-2014 Geotools. All Rights Reserved.