Interface SimpleFeature
- All Superinterfaces:
Attribute
,ComplexAttribute
,Feature
,Property
- All Known Implementing Classes:
DecoratingFeature
,JDBCFeatureReader.ResultSetFeature
,MongoDBObjectFeature
,MongoFeature
,PreGeneralizedSimpleFeature
,SimpleFeatureImpl
SimpleFeatureType
composed of fixed list values in a known order.
The definition of a "simple feature" can be summed up as the following:
- made up of only non-complex attributes, no associations
- attributes are of multiplicity 1
- attributes are ordered
- attribute names are unqualified (namespaceURI == null)
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:
-
Method Summary
Modifier and TypeMethodDescriptiongetAttribute
(int index) Gets an attribute value by index.getAttribute
(String name) Gets an attribute value by name.getAttribute
(Name name) Gets an attribute value by name.int
The number of attributes the feature is composed of.Returns a list of the values of the attributes contained by the feature.Returns the value of the default geometry of the feature.The type of the feature.getID()
Unique Identifier for the SimpleFeaturegetType()
Override and type narrow to SimpleFeatureType.void
setAttribute
(int index, Object value) Sets an attribute value by index.void
setAttribute
(String name, Object value) Sets an attribute value by name.void
setAttribute
(Name name, Object value) Sets an attribute value by name.void
setAttributes
(Object[] values) Sets the values of the attributes contained by the feature.void
setAttributes
(List<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 Attribute
getDescriptor
Methods inherited from interface ComplexAttribute
getProperties, getProperties, getProperties, getProperty, getProperty, getValue, setValue, validate
Methods inherited from interface Feature
getBounds, getDefaultGeometryProperty, getIdentifier, setDefaultGeometryProperty
Methods inherited from interface Property
getName, getUserData, hasUserData, isNillable, setValue
-
Method Details
-
getID
String getID()Unique Identifier for the SimpleFeatureThis 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. -
getFeatureType
SimpleFeatureType getFeatureType()The type of the feature.This method is a synonym for
getType()
.- See Also:
-
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
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
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
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
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
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
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
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
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 getDefaultGeometryProperty().getValue();
- Returns:
- The default geometry, or
null
if no default geometry attribute exists.
-
setDefaultGeometry
Sets the value of the default geometry for the feature.This method is convenience for:
getDefaultGeometryProperty().setValue(geometry);
- Parameters:
geometry
- The new default geometry value.
-