Class 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 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
    • Constructor Detail

      • FeatureTypes

        public FeatureTypes()
    • 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,
                                                  boolean forceOnlyMissing,
                                                  boolean onlyIfCompatible)
                                           throws SchemaException
        Forces the specified CRS on geometry attributes (all or some, depends on the parameters).
        Parameters:
        schema - the original schema
        crs - the forced crs
        forceOnlyMissing - if true, will force the specified crs only on the attributes that do miss one
        onlyIfCompatible - 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
      • 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 reprojected
        crs - 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 calling newFeatureType(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 calling newFeatureType(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 calling newFeatureType(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 question
        name - 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 question
        namespace - 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)
      • equalsExact

        public static boolean equalsExact​(SimpleFeatureType typeA,
                                          SimpleFeatureType typeB)
        Exact equality based on typeNames, namespace, attributes and ancestors, including the user maps contents
      • equalsAncestors

        public static boolean equalsAncestors​(SimpleFeatureType typeA,
                                              SimpleFeatureType typeB)
        This method depends on the correct implementation of FeatureType equals

        We may need to write an implementation that can detect cycles,