Package org.geotools.feature
Class FeatureTypes
- Object
-
- FeatureTypes
-
public class FeatureTypes extends Object
Utility methods for working against the FeatureType interface.Many methods from DataUtilities should be refractored here.
Responsibilities:
- Schema construction from String spec
- Schema Force CRS
- Since:
- 2.1.M3
- Author:
- Jody Garnett, Refractions Research
-
-
Field Summary
Fields Modifier and Type Field Description static SimpleFeatureType
ABSTRACT_FEATURE_TYPE
abstract base type for all feature typesstatic int
ANY_LENGTH
represent an unbounded field lengthstatic URI
DEFAULT_NAMESPACE
the default namespace for feature typesstatic NameImpl
DEFAULT_TYPENAME
default feature collection namestatic SimpleFeatureType
EMPTY
An feature type with no attributesprotected static FilterFactory
FF
-
Constructor Summary
Constructors Constructor Description FeatureTypes()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Set<FeatureType>
ancestors(SimpleFeatureType featureType)
static Filter
createFieldOptions(Collection<?> options)
Creates a restriction limiting an attribute to a given list of values.static Filter
createLengthRestriction(int length)
Creates a restriction based on the attribute value lengthstatic boolean
equals(List<AttributeDescriptor> attributesA, List<AttributeDescriptor> attributesB)
static boolean
equals(SimpleFeatureType typeA, SimpleFeatureType typeB)
Exact equality based on typeNames, namespace, attributes and ancestorsstatic boolean
equals(AttributeDescriptor[] attributesA, AttributeDescriptor[] attributesB)
static boolean
equals(AttributeDescriptor a, AttributeDescriptor b)
static boolean
equalsAncestors(SimpleFeatureType typeA, SimpleFeatureType typeB)
This method depends on the correct implementation of FeatureType equalsstatic boolean
equalsExact(List<AttributeDescriptor> attributesA, List<AttributeDescriptor> attributesB)
static boolean
equalsExact(SimpleFeatureType typeA, SimpleFeatureType typeB)
Exact equality based on typeNames, namespace, attributes and ancestors, including the user maps contentsstatic boolean
equalsExact(AttributeDescriptor[] attributesA, AttributeDescriptor[] attributesB)
static boolean
equalsExact(AttributeDescriptor a, AttributeDescriptor b)
static boolean
equalsId(SimpleFeatureType typeA, SimpleFeatureType typeB)
Quick check of namespace and typenamestatic List<FeatureType>
getAncestors(FeatureType featureType)
Walks up the type hierarchy of the feature returning all super types of the specified feature type.static int
getFieldLength(PropertyDescriptor descriptor)
This is a 'suitable replacement for extracting the expected field length of an attribute absed on its "facets" (ie Filter describing type restrictions);static List<?>
getFieldOptions(PropertyDescriptor descriptor)
Returns the eventual list of possible values accepted by thisstatic boolean
isDecendedFrom(FeatureType featureType, URI namespace, String typeName)
A query of the the types ancestor information.static boolean
isDecendedFrom(FeatureType featureType, FeatureType isParentType)
static boolean
matches(FeatureType featureType, Name name)
Whether the feature type has the specified name, or is a descendent from itstatic SimpleFeatureType
newFeatureType(AttributeDescriptor[] types, String name)
Create a new FeatureType with the given AttributeTypes.static SimpleFeatureType
newFeatureType(AttributeDescriptor[] types, String name, URI ns)
Create a new FeatureType with the given AttributeTypes.static SimpleFeatureType
newFeatureType(AttributeDescriptor[] types, String name, URI ns, boolean isAbstract)
Create a new FeatureType with the given AttributeTypes.static SimpleFeatureType
newFeatureType(AttributeDescriptor[] types, String name, URI ns, boolean isAbstract, SimpleFeatureType[] superTypes)
The most specific way to create a new FeatureType.static SimpleFeatureType
newFeatureType(AttributeDescriptor[] types, String name, URI ns, boolean isAbstract, SimpleFeatureType[] superTypes, AttributeDescriptor defaultGeometry)
The most specific way to create a new FeatureType.static SimpleFeatureType
newFeatureType(AttributeDescriptor[] types, String name, URI ns, boolean isAbstract, SimpleFeatureType[] superTypes, GeometryDescriptor defaultGeometry)
The most specific way to create a new FeatureType.static boolean
shouldReproject(SimpleFeatureType schema, CoordinateReferenceSystem crs)
Tells if there is any work to be done for reprojection, i.e. if there are any CRS that differ but are compatible.static SimpleFeature
transform(SimpleFeature feature, SimpleFeatureType schema, MathTransform transform)
Applies transform to all geometry attribute.static SimpleFeatureType
transform(SimpleFeatureType schema, CoordinateReferenceSystem crs)
Forces the specified CRS on all geometry attributesstatic SimpleFeatureType
transform(SimpleFeatureType schema, CoordinateReferenceSystem crs, boolean forceOnlyMissing)
Forces the specified CRS on geometry attributes (all or some, depends on the parameters).static SimpleFeatureType
transform(SimpleFeatureType schema, CoordinateReferenceSystem crs, boolean forceOnlyMissing, boolean onlyIfCompatible)
Forces the specified CRS on geometry attributes (all or some, depends on the parameters).
-
-
-
Field Detail
-
DEFAULT_NAMESPACE
public static final URI DEFAULT_NAMESPACE
the default namespace for feature types
-
ABSTRACT_FEATURE_TYPE
public static final SimpleFeatureType ABSTRACT_FEATURE_TYPE
abstract base type for all feature types
-
DEFAULT_TYPENAME
public static final NameImpl DEFAULT_TYPENAME
default feature collection name
-
ANY_LENGTH
public static final int ANY_LENGTH
represent an unbounded field length- See Also:
- Constant Field Values
-
EMPTY
public static final SimpleFeatureType EMPTY
An feature type with no attributes
-
FF
protected static FilterFactory FF
-
-
Method Detail
-
createLengthRestriction
public static Filter createLengthRestriction(int length)
Creates a restriction based on the attribute value length- Parameters:
length
- The maximum allowed length- Returns:
- The restriction
-
getFieldLength
public static int getFieldLength(PropertyDescriptor descriptor)
This is a 'suitable replacement for extracting the expected field length of an attribute absed on its "facets" (ie Filter describing type restrictions);This code is copied from the ShapefileDataStore where it was written (probably by dzwiers). Cholmes is providing documentation.
- Parameters:
descriptor
- the descriptor whose lenght is to be investigated- Returns:
- an int indicating the max length of field in characters, or ANY_LENGTH
-
getFieldOptions
public static List<?> getFieldOptions(PropertyDescriptor descriptor)
Returns the eventual list of possible values accepted by this- Parameters:
descriptor
-- Returns:
-
createFieldOptions
public static Filter createFieldOptions(Collection<?> options)
Creates a restriction limiting an attribute to a given list of values.- Parameters:
options
- The list of all possible values- Returns:
- A filter restricting the attribute to the given list of values
-
transform
public static SimpleFeatureType transform(SimpleFeatureType schema, CoordinateReferenceSystem crs) throws SchemaException
Forces the specified CRS on all geometry attributes- Parameters:
schema
- the original schemacrs
- the forced crs- Throws:
SchemaException
-
transform
public static SimpleFeatureType transform(SimpleFeatureType schema, CoordinateReferenceSystem crs, boolean forceOnlyMissing) throws SchemaException
Forces the specified CRS on geometry attributes (all or some, depends on the parameters).- Parameters:
schema
- the original schemacrs
- the forced crsforceOnlyMissing
- if true, will force the specified crs only on the attributes that do miss one- Throws:
SchemaException
-
transform
public static SimpleFeatureType transform(SimpleFeatureType schema, CoordinateReferenceSystem crs, boolean forceOnlyMissing, boolean onlyIfCompatible) throws SchemaException
Forces the specified CRS on geometry attributes (all or some, depends on the parameters).- Parameters:
schema
- the original schemacrs
- the forced crsforceOnlyMissing
- if true, will force the specified crs only on the attributes that do miss oneonlyIfCompatible
- if true, will force the specified crs only if the original CRS is compatible with it. This property is ignored if forceOnlyMissing is true.- Throws:
SchemaException
-
transform
public static SimpleFeature transform(SimpleFeature feature, SimpleFeatureType schema, MathTransform transform) throws MismatchedDimensionException, TransformException, IllegalAttributeException
Applies transform to all geometry attribute.- Parameters:
feature
- Feature to be transformedschema
- Schema for target transformation - transform( schema, crs )transform
- MathTransform used to transform coordinates - reproject( crs, crs )- Returns:
- transformed Feature of type schema
- Throws:
MismatchedDimensionException
TransformException
IllegalAttributeException
-
shouldReproject
public static boolean shouldReproject(SimpleFeatureType schema, CoordinateReferenceSystem crs)
Tells if there is any work to be done for reprojection, i.e. if there are any CRS that differ but are compatible.- Parameters:
schema
- the schema to be reprojectedcrs
- the crs to reproject to- Returns:
- answer as boolean
-
newFeatureType
public static SimpleFeatureType newFeatureType(AttributeDescriptor[] types, String name, URI ns, boolean isAbstract, SimpleFeatureType[] superTypes) throws FactoryRegistryException, SchemaException
The most specific way to create a new FeatureType.- Parameters:
types
- The AttributeTypes to create the FeatureType with.name
- The typeName of the FeatureType. Required, may not be null.ns
- The namespace of the FeatureType. Optional, may be null.isAbstract
- True if this created type should be abstract.superTypes
- A Collection of types the FeatureType will inherit from. Currently, all types inherit from feature in the opengis namespace.- Returns:
- A new FeatureType created from the given arguments.
- Throws:
FactoryRegistryException
- If there are problems creating a factory.SchemaException
- If the AttributeTypes provided are invalid in some way.
-
newFeatureType
public static SimpleFeatureType newFeatureType(AttributeDescriptor[] types, String name, URI ns, boolean isAbstract, SimpleFeatureType[] superTypes, AttributeDescriptor defaultGeometry) throws FactoryRegistryException, SchemaException
The most specific way to create a new FeatureType.- Parameters:
types
- The AttributeTypes to create the FeatureType with.name
- The typeName of the FeatureType. Required, may not be null.ns
- The namespace of the FeatureType. Optional, may be null.isAbstract
- True if this created type should be abstract.superTypes
- A Collection of types the FeatureType will inherit from. Currently, all types inherit from feature in the opengis namespace.- Returns:
- A new FeatureType created from the given arguments.
- Throws:
FactoryRegistryException
- If there are problems creating a factory.SchemaException
- If the AttributeTypes provided are invalid in some way.
-
newFeatureType
public static SimpleFeatureType newFeatureType(AttributeDescriptor[] types, String name, URI ns, boolean isAbstract, SimpleFeatureType[] superTypes, GeometryDescriptor defaultGeometry) throws FactoryRegistryException, SchemaException
The most specific way to create a new FeatureType.- Parameters:
types
- The AttributeTypes to create the FeatureType with.name
- The typeName of the FeatureType. Required, may not be null.ns
- The namespace of the FeatureType. Optional, may be null.isAbstract
- True if this created type should be abstract.superTypes
- A Collection of types the FeatureType will inherit from. Currently, all types inherit from feature in the opengis namespace.- Returns:
- A new FeatureType created from the given arguments.
- Throws:
FactoryRegistryException
- If there are problems creating a factory.SchemaException
- If the AttributeTypes provided are invalid in some way.
-
newFeatureType
public static SimpleFeatureType newFeatureType(AttributeDescriptor[] types, String name, URI ns, boolean isAbstract) throws FactoryRegistryException, SchemaException
Create a new FeatureType with the given AttributeTypes. A short cut for callingnewFeatureType(types,name,ns,isAbstract,null)
.- Parameters:
types
- The AttributeTypes to create the FeatureType with.name
- The typeName of the FeatureType. Required, may not be null.ns
- The namespace of the FeatureType. Optional, may be null.isAbstract
- True if this created type should be abstract.- Returns:
- A new FeatureType created from the given arguments.
- Throws:
FactoryRegistryException
- If there are problems creating a factory.SchemaException
- If the AttributeTypes provided are invalid in some way.
-
newFeatureType
public static SimpleFeatureType newFeatureType(AttributeDescriptor[] types, String name, URI ns) throws FactoryRegistryException, SchemaException
Create a new FeatureType with the given AttributeTypes. A short cut for callingnewFeatureType(types,name,ns,false,null)
.- Parameters:
types
- The AttributeTypes to create the FeatureType with.name
- The typeName of the FeatureType. Required, may not be null.ns
- The namespace of the FeatureType. Optional, may be null.- Returns:
- A new FeatureType created from the given arguments.
- Throws:
FactoryRegistryException
- If there are problems creating a factory.SchemaException
- If the AttributeTypes provided are invalid in some way.
-
newFeatureType
public static SimpleFeatureType newFeatureType(AttributeDescriptor[] types, String name) throws FactoryRegistryException, SchemaException
Create a new FeatureType with the given AttributeTypes. A short cut for callingnewFeatureType(types,name,null,false,null)
. Useful for test cases or datasources which may not allow a namespace.- Parameters:
types
- The AttributeTypes to create the FeatureType with.name
- The typeName of the FeatureType. Required, may not be null.- Returns:
- A new FeatureType created from the given arguments.
- Throws:
FactoryRegistryException
- If there are problems creating a factory.SchemaException
- If the AttributeTypes provided are invalid in some way.
-
getAncestors
public static List<FeatureType> getAncestors(FeatureType featureType)
Walks up the type hierarchy of the feature returning all super types of the specified feature type. The search terminates when a non-FeatureType or null is found. The original featureType is not included as an ancestor, only its strict ancestors.
-
matches
public static boolean matches(FeatureType featureType, Name name)
Whether the feature type has the specified name, or is a descendent from it- Parameters:
featureType
- typeName with parentage in questionname
- name to match against- Returns:
- true if featureType has the same name, or is a descendent of the indicated name
-
isDecendedFrom
public static boolean isDecendedFrom(FeatureType featureType, URI namespace, String typeName)
A query of the the types ancestor information.This utility method may be used as common implementation for
FeatureType.isDecendedFrom( namespace, typeName )
, however for specific uses, such as GML, an implementor may be able to provide a more efficient implemenation based on prior knolwege.This is a proper check, if the provided FeatureType matches the given namespace and typename it is not considered to be decended from itself.
- Parameters:
featureType
- typeName with parentage in questionnamespace
- namespace to match against, or null for a "wildcard"typeName
- typename to match against, or null for a "wildcard"- Returns:
- true if featureType is a decendent of the indicated namespace & typeName
-
isDecendedFrom
public static boolean isDecendedFrom(FeatureType featureType, FeatureType isParentType)
-
equals
public static boolean equals(SimpleFeatureType typeA, SimpleFeatureType typeB)
Exact equality based on typeNames, namespace, attributes and ancestors
-
equalsExact
public static boolean equalsExact(SimpleFeatureType typeA, SimpleFeatureType typeB)
Exact equality based on typeNames, namespace, attributes and ancestors, including the user maps contents
-
equals
public static boolean equals(List<AttributeDescriptor> attributesA, List<AttributeDescriptor> attributesB)
-
equalsExact
public static boolean equalsExact(List<AttributeDescriptor> attributesA, List<AttributeDescriptor> attributesB)
-
equals
public static boolean equals(AttributeDescriptor[] attributesA, AttributeDescriptor[] attributesB)
-
equalsExact
public static boolean equalsExact(AttributeDescriptor[] attributesA, AttributeDescriptor[] attributesB)
-
equalsAncestors
public static boolean equalsAncestors(SimpleFeatureType typeA, SimpleFeatureType typeB)
This method depends on the correct implementation of FeatureType equalsWe may need to write an implementation that can detect cycles,
-
ancestors
public static Set<FeatureType> ancestors(SimpleFeatureType featureType)
-
equals
public static boolean equals(AttributeDescriptor a, AttributeDescriptor b)
-
equalsExact
public static boolean equalsExact(AttributeDescriptor a, AttributeDescriptor b)
-
equalsId
public static boolean equalsId(SimpleFeatureType typeA, SimpleFeatureType typeB)
Quick check of namespace and typename
-
-