Class DataUtilities

    • Constructor Detail

      • DataUtilities

        public DataUtilities()
    • Method Detail

      • attributeNames

        public static String[] attributeNames​(SimpleFeatureType featureType)
        Retrieve the attributeNames defined by the featureType
        Returns:
        array of simple attribute names
      • attributeNames

        public static String[] attributeNames​(Filter filter,
                                              SimpleFeatureType featureType)
        Traverses the filter and returns any encountered property names.

        The feature type is supplied as contexts used to lookup expressions in cases where the attributeName does not match the actual name of the type.

      • propertyNames

        public static Set<PropertyName> propertyNames​(Filter filter,
                                                      SimpleFeatureType featureType)
        Traverses the filter and returns any encountered property names.

        The feature type is supplied as contexts used to lookup expressions in cases where the attributeName does not match the actual name of the type.

      • attributeNames

        public static String[] attributeNames​(Filter filter)
        Traverses the filter and returns any encountered property names.
      • propertyNames

        public static Set<PropertyName> propertyNames​(Filter filter)
        Traverses the filter and returns any encountered property names.
      • attributeNames

        public static String[] attributeNames​(Expression expression,
                                              SimpleFeatureType featureType)
        Traverses the expression and returns any encountered property names.

        The feature type is supplied as contexts used to lookup expressions in cases where the attributeName does not match the actual name of the type.

      • propertyNames

        public static Set<PropertyName> propertyNames​(Expression expression,
                                                      SimpleFeatureType featureType)
        Traverses the expression and returns any encountered property names.

        The feature type is supplied as contexts used to lookup expressions in cases where the attributeName does not match the actual name of the type.

      • attributeNames

        public static String[] attributeNames​(Expression expression)
        Traverses the expression and returns any encountered property names.
      • propertyNames

        public static Set<PropertyName> propertyNames​(Expression expression)
        Traverses the expression and returns any encountered property names.
      • compare

        public static int compare​(SimpleFeatureType typeA,
                                  SimpleFeatureType typeB)
        Compare attribute coverage between two feature types (allowing the identification of subTypes).

        Strict compatibility is assumed meaning that both the local name and java binding are compatible (see compareInternal(SimpleFeatureType, SimpleFeatureType, boolean) for more details.

        Namespace is not considered in this operations. You may still need to reType to get the correct namespace, or reorder.

        Please note this method will not result in a stable sort if used in a Comparator as -1 is used to indicate incompatiblity (rather than simply "before").

        Parameters:
        typeA - FeatureType being compared
        typeB - FeatureType being compared against
      • compareNames

        public static int compareNames​(SimpleFeatureType typeA,
                                       SimpleFeatureType typeB)
        Compare attribute coverage between two feature types (allowing the identification of subTypes).

        loose compatibility is assumed based on local name (java binding may differ) (see compareInternal(SimpleFeatureType, SimpleFeatureType, boolean) for more details.

        Namespace is not considered in this operations. You may still need to reType to get the correct namespace, or reorder.

        Please note this method will not result in a stable sort if used in a Comparator as -1 is used to indicate incompatiblity (rather than simply "before").

        Parameters:
        typeA - FeatureType being compared
        typeB - FeatureType being compared against
      • compareInternal

        protected static int compareInternal​(SimpleFeatureType typeA,
                                             SimpleFeatureType typeB,
                                             boolean strict)
        Compare attribute coverage between two feature types (allowing the identification of subTypes).

        The comparison results in a number with the following meaning:

        • 1: if typeA is a sub type/reorder/renamespace of typeB
        • 0: if typeA and typeB are the same type
        • -1: if typeA is not subtype of typeB

        Comparison is based on AttributeDescriptor - the isMatch(AttributeDescriptor, AttributeDescriptor, boolean) method is used to quickly confirm that the local name and java binding (depending on strict flag value) are compatible.

        Namespace is not considered in this operations. You may still need to reType to get the correct namespace, or reorder.

        Please note this method will not result in a stable sort if used in a Comparator as -1 is used to indicate incompatiblity (rather than simply "before").

        Parameters:
        typeA - FeatureType being compared
        typeB - FeatureType being compared against
        strict - flag controlling the comparison check
      • isMatch

        public static boolean isMatch​(AttributeDescriptor a,
                                      AttributeDescriptor b)
        Quickly check if two descriptors are at all compatible.

        This method checks the descriptors name and class binding to see if the values have any chance of being compatible. Strict compatibility assumed (see also isMatch(AttributeDescriptor, AttributeDescriptor, boolean).

        Parameters:
        a - descriptor to compare
        b - descriptor to compare
        Returns:
        true to the descriptors name and binding class match
      • isMatch

        public static boolean isMatch​(AttributeDescriptor a,
                                      AttributeDescriptor b,
                                      boolean strict)
        Quickly check descriptors compatibility.

        This method checks the descriptors name and class binding to see if the values have any chance of being compatible.

        Parameters:
        a - descriptor to compare
        b - descriptor to compare
        strict - if true both descriptor name and class binding is checked otherwise a more loose form o compatibility is assumed where equality is determined by descriptor name only
        Returns:
        true if compatibility comparison succeeds
      • reType

        public static SimpleFeature reType​(SimpleFeatureType featureType,
                                           SimpleFeature feature,
                                           boolean duplicate)
                                    throws IllegalAttributeException
        Retypes the feature to match the provided featureType.

        The duplicate parameter indicates how the new feature is to be formed:

        • dupliate is true: A "deep copy" is made of each attribute resulting in a safe "copy"Adjusts the attribute order to match the provided featureType.
        • duplicate is false: the attributes are simply reordered and are actually the same instances as those in the origional feature
        In the future this method may simply return a "wrapper" when duplicate is false.

        Parameters:
        duplicate - True to perform duplicate(Object) on each attribute
        Throws:
        IllegalAttributeException
      • duplicate

        public static Object duplicate​(Object src)
        Performs a deep copy of the provided object.

        A number of tricks are used to make this as fast as possible:

        • Simple or Immutable types are copied as is (String, Integer, Float, URL, etc..)
        • JTS Geometry objects are cloned
        • Arrays and the Collection classes are duplicated element by element
        This function is used recusively for (in order to handle complext features) no attempt is made to detect cycles at this time so your milage may vary.
        Parameters:
        src - Source object
        Returns:
        copy of source object
      • defaultValues

        public static Object[] defaultValues​(SimpleFeatureType featureType)
        Produce a set of default values for the provided FeatureType
        Returns:
        Array of values, that are good starting point for data entry
      • template

        public static SimpleFeature template​(SimpleFeatureType featureType,
                                             Object... providedValues)
        Create a new feature from the provided values, using appropriate default values for any nulls provided.
        Returns:
        newly created feature
        Throws:
        ArrayIndexOutOfBoundsException - If the number of provided values does not match the featureType
      • template

        public static SimpleFeature template​(SimpleFeatureType featureType,
                                             String featureID,
                                             Object... providedValues)
        Create a new feature from the provided values, using appropriate default values for any nulls provided.
        Parameters:
        providedValues - provided attributes
        Returns:
        newly created feature
        Throws:
        ArrayIndexOutOfBoundsException - If the number of provided values does not match the featureType
      • defaultValues

        public static Object[] defaultValues​(SimpleFeatureType featureType,
                                             Object... values)
        Create default values matching the provided feature type.
        Returns:
        set of default values
        Throws:
        ArrayIndexOutOfBoundsException - If the number of provided values does not match the featureType
      • defaultValue

        public static Object defaultValue​(Class type)
        Returns a non-null default value for the class that is passed in. This is a helper class an can't create a default class for all types but it does support:
        • String
        • Object - will return empty string
        • Integer
        • Double
        • Long
        • Short
        • Float
        • BigDecimal
        • BigInteger
        • Character
        • Boolean
        • UUID
        • Timestamp
        • java.sql.Date
        • java.sql.Time
        • java.util.Date
        • JTS Geometries
        • Arrays - will return an empty array of the appropriate type
      • source

        public static SimpleFeatureSource source​(SimpleFeature... featureArray)
        Wrap up an array of features as a FeatureSource.
        Parameters:
        featureArray - Array of features
        Returns:
        FeatureSource
      • source

        public static SimpleFeatureSource source​(FeatureCollection<SimpleFeatureType,​SimpleFeature> collection)
        Wraps up the provided feature collection in as a SimpleFeatureSource.

        This is usually done for use by the renderer; allowing it to query the feature collection as required.

        Parameters:
        collection - Feature collection providing content
        Returns:
        FeatureSource used to wrap the content
        Throws:
        NullPointerException - if any of the features are null
        IllegalArgumentException - If the provided collection is inconsistent (perhaps containing mixed feature types)
      • dataStore

        public static DataStore dataStore​(SimpleFeatureCollection features)
        Adapt a feature collection as a read-only DataStore.

        See UserLayer for example use.

        Parameters:
        features - feature collection to adap
        Returns:
        read-only DataStore
      • dataStore

        public static DataStore dataStore​(SimpleFeatureSource source)
        Adapt a single FeatureSource as a read-only DataStore.

        See UserLayer for example use.

        Parameters:
        source - Feature source to adapt
        Returns:
        read-only DataStore
      • collection

        public static SimpleFeatureCollection collection​(SimpleFeature... features)
        Copies the provided features into a FeatureCollection.

        Often used when gathering features for FeatureStore:

         
         featureStore.addFeatures( DataUtilities.collection(array));
         
         
        Parameters:
        features - Array of features
        Returns:
        FeatureCollection
      • collection

        public static DefaultFeatureCollection collection​(FeatureCollection<SimpleFeatureType,​SimpleFeature> featureCollection)
        Copies the provided features into a FeatureCollection.

        Often used when gathering a SimpleFeatureCollection into memory.

        Parameters:
        featureCollection - the features to add to a new feature collection.
        Returns:
        FeatureCollection
      • close

        public static void close​(Iterator<?> iterator)
        Checks if the provided iterator implements Closeable.

        Any problems are logged at Level.FINE.

      • first

        public static <F extends Feature> F first​(FeatureCollection<?,​F> featureCollection)
        Obtain the first feature from the collection as an exemplar.
        Returns:
        first feature from the featureCollection
      • simple

        public static SimpleFeatureCollection simple​(FeatureCollection<SimpleFeatureType,​SimpleFeature> featureCollection)
        A safe cast to SimpleFeatureCollection; that will introduce a wrapper if it has to.

        Please keep the use of this class to a minimum; if you are expecting a FeatureCollection please make use of SimpleFeatureCollection if you possibly can.

        So when are you stuck using this class?:

        • Offering backwards compatible constructors for legacy code prior to 2.7
        • implementing FeatureStore.addFeatures(...) since we cannot type narrow parameters
        Parameters:
        featureCollection - will be returned as a SimpleFeatureCollection and wrapped only if needed
        Returns:
        SimpleFeatureCollection
        Since:
        2.7
      • simple

        public static SimpleFeatureSource simple​(FeatureSource source)
        A safe cast to SimpleFeatureSource; that will introduce a wrapper if it has to.

        Please keep the use of this class to a minimum; if you are expecting a FeatureSource please make use of SimpleFeatureSource if you possibly can.

        Since:
        2.7
      • simple

        public static SimpleFeatureStore simple​(FeatureStore store)
        A safe cast to SimpleFeatureStore; that will introduce a wrapper if it has to.

        Please keep the use of this class to a minimum; if you are expecting a FeatureStore please make use of SimpleFeatureStore if you possibly can.

        Since:
        2.7
      • simple

        public static SimpleFeatureType simple​(FeatureType featureType)
                                        throws DataSourceException
        Go through FeatureType description and convert to a SimpleFeatureType. Also ignores AbstractFeatureType contributions such as name etc...
        Parameters:
        featureType - FeatureType being converted
        Returns:
        SimpleFeatureType created by stripping any complicated content from the provided featureType
        Throws:
        DataSourceException
      • simple

        public static SimpleFeatureLocking simple​(FeatureLocking locking)
        A safe cast to SimpleFeatureLocking; that will introduce a wrapper if it has to.

        Please keep the use of this class to a minimum; if you are expecting a FeatureLocking please make use of SimpleFeatureLocking if you possibly can.

        Since:
        2.7
      • list

        public static <F extends FeatureList<F> list​(FeatureCollection<?,​F> featureCollection)
        Copies the provided features into a List.
        Returns:
        List of features copied into memory
      • list

        public static <F extends FeatureList<F> list​(FeatureCollection<?,​F> featureCollection,
                                                       int maxFeatures)
        Copies the provided fetaures into a List.
        Parameters:
        maxFeatures - Maximum number of features to load
        Returns:
        List of features copied into memory
      • iterator

        public static <F extends FeatureIterator<F> iterator​(FeatureIterator<F> featureIterator)
        Iteator wrapped around the provided FeatureIterator, implementing Closeable.
        Returns:
        Iterator wrapped around provided FeatureIterator, implements Closeable
        See Also:
        close(Iterator)
      • fidSet

        public static Set<String> fidSet​(FeatureCollection<?,​?> featureCollection)
        Copies the feature ids from each and every feature into a set.

        This method can be slurp an in memory record of the contents of a

      • collectionCast

        public static <F extends FeatureCollection<F> collectionCast​(FeatureCollection<?,​F> featureCollection)
        Used to quickly cast to a java.util.Collection.
        Returns:
        Collection
      • collection

        public static SimpleFeatureCollection collection​(List<SimpleFeature> list)
        Copies the provided features into a FeatureCollection.

        Often used when gathering a SimpleFeatureCollection into memory.

        Parameters:
        list - features to add to a new FeatureCollection
        Returns:
        FeatureCollection
      • collection

        public static SimpleFeatureCollection collection​(SimpleFeature feature)
        Copies the provided features into a FeatureCollection.

        Often used when gathering features for FeatureStore:

         
         featureStore.addFeatures( DataUtilities.collection(feature));
         
         
        Parameters:
        feature - a feature to add to a new collection
        Returns:
        FeatureCollection
      • collection

        public static SimpleFeatureCollection collection​(SimpleFeatureIterator reader)
                                                  throws IOException
        Copies the provided reader into a FeatureCollection, reader will be closed.

        Often used when gathering features for FeatureStore:

         
         featureStore.addFeatures( DataUtilities.collection(reader));
         
         
        Returns:
        FeatureCollection
        Throws:
        IOException
      • attributesEqual

        public static boolean attributesEqual​(Object att,
                                              Object otherAtt)
        Used to compare if two values are equal.

        This method is here to work around the fact that JTS Geometry requires a specific method to be called rather than object.equals.

        This method uses:

        Parameters:
        att - Attribute value
        otherAtt - Other value
        Returns:
        True if the values are equal
      • createSubType

        public static SimpleFeatureType createSubType​(SimpleFeatureType featureType,
                                                      String[] properties,
                                                      CoordinateReferenceSystem override)
                                               throws SchemaException
        Create a derived FeatureType
        Parameters:
        featureType - Original feature type to derive from.
        properties - If null, every property of the featureType in input will be used
        override - Intended CoordinateReferenceSystem, if null original will be used
        Returns:
        derived FeatureType
        Throws:
        SchemaException
      • createSubType

        public static SimpleFeatureType createSubType​(SimpleFeatureType featureType,
                                                      String[] properties,
                                                      CoordinateReferenceSystem override,
                                                      String typeName,
                                                      URI namespace)
                                               throws SchemaException
        Create a derived FeatureType
        Parameters:
        featureType - Original feature type to derive from.
        properties - If null, every property of the featureType in input will be used
        override - Intended CoordinateReferenceSystem, if null original will be used
        typeName - Type name override
        namespace - Namespace override
        Returns:
        derived FeatureType
        Throws:
        SchemaException
      • createType

        public static SimpleFeatureType createType​(String typeName,
                                                   String typeSpec)
                                            throws SchemaException
        Utility method for FeatureType construction.

        Will parse a String of the form: "name:Type,name2:Type2,..."

        Where Type is defined by createAttribute(java.lang.String):

        • Each attribute descriptor is defined using the form: "name:Type:hint"
        • Where Type is:
          • 0,Interger,int: represents Interger
          • 0.0, Double, double: represents Double
          • "",String,string: represents String
          • Geometry: represents Geometry, additional common geometry types supported including Point,LineString,Polygon,MultiLineString,MultiPolygon,MultiPoint,GeometryCollection
        • UUID
        • Date
        • full.class.path: represents java type
      • Where hint is "hint1;hint2;...;hintN", in which "hintN" is one of:
        • nillable
        • authority=text
        • srid=number
      • You may indicate the default Geometry with an astrix: "*geom:Geometry".
      • You may also indicate the srid (used to look up a EPSG code): "*point:Point:3226"
      • The CRS authority can be specified using the authority hint, if it's not EPSG (the default): "*point:Point:authority=IAU;srid=49900"

        Examples:

        • name:"",age:0,geom:Geometry,centroid:Point,url:java.io.URL"
        • id:String,polygonProperty:Polygon:srid=32615
        • id:String,polygonProperty:Polygon:authority=IAU;srid=1000
        • identifier:UUID,location:Point,*area:MultiPolygon,created:Date
        • uuid:UUID,name:String,description:String,time:java.sql.Timestamp
Parameters:
typeName - identification of FeatureType: (namesapce).typeName
typeSpec - Specification of FeatureType attributes "name:Type,name2:Type2,..."
Throws:
SchemaException