Class DataUtilities

Object
DataUtilities

public class DataUtilities extends Object
Utility functions for use with GeoTools with data classes.

These methods fall into several categories:

Conversion between common data structures.

SimpleFeatureType and SimpleFeature encoding/decoding from String as used by the PropertyDataStore tutorials.

Working with SimpleFeatureType (this class is immutable so we always have to make a modified copy):

Manipulating individual features and data values:

And a grab bag of helpful utility methods for those implementing a DataStore:
Author:
Jody Garnett, Refractions Research
  • Constructor Details

    • DataUtilities

      public DataUtilities()
  • Method Details

    • 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) throws IllegalAttributeException
      Creates duplicate of feature adjusted to the provided featureType.

      Please note this implementation provides "deep copy" using duplicate(Object) to copy each attribute.

      Parameters:
      featureType - FeatureType requested
      feature - Origional Feature from DataStore
      Returns:
      An instance of featureType based on feature
      Throws:
      IllegalAttributeException - If opperation could not be performed
    • 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
    • template

      public static SimpleFeature template(SimpleFeatureType featureType) throws IllegalAttributeException
      Constructs an empty feature to use as a Template for new content.

      We may move this functionality to FeatureType.create( null )?

      Parameters:
      featureType - Type of feature we wish to create
      Returns:
      A new Feature of type featureType
      Throws:
      IllegalAttributeException
    • template

      public static SimpleFeature template(SimpleFeatureType featureType, String featureID)
      Use the provided featureType to create an empty feature.

      The defaultValues(SimpleFeatureType) method is used to generate the intial values (making use of AttributeDescriptor.getDefaultValue() as required.

      Returns:
      Craeted feature
    • 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
    • reader

      public static FeatureReader<SimpleFeatureType,SimpleFeature> reader(SimpleFeature... features) throws IOException
      Creates a FeatureReader<SimpleFeatureType, SimpleFeature> for testing.
      Parameters:
      features - Array of features
      Returns:
      FeatureReader<SimpleFeatureType, SimpleFeature> spaning provided feature array
      Throws:
      IOException - If provided features Are null or empty
    • source

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

      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)
    • createView

      public static SimpleFeatureSource createView(DataStore store, Query query) throws IOException, SchemaException
      Return a 'view' of the given DataStore constrained by a Query.
      Parameters:
      store - the data store
      query - the query
      Returns:
      the constrained view
      Throws:
      IOException - if the data store cannot be accessed
      SchemaException - if the query is incompatible with the store's contents
    • createView

      public static SimpleFeatureSource createView(SimpleFeatureSource source, Query query) throws IOException, SchemaException
      Return a 'view' of the given FeatureSource constrained by a Query.
      Parameters:
      source - feature source
      query - the query
      Returns:
      the constrained view
      Throws:
      IOException - if the data store cannot be accessed
      SchemaException - if the query is incompatible with the store's contents
    • 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
    • reader

      Adapt a collection to a reader for use with FeatureStore.setFeatures( reader ).
      Parameters:
      collection - Collection of SimpleFeature
      Returns:
      FeatureRedaer over the provided contents
      Throws:
      IOException - IOException if there is any problem reading the content.
    • reader

      Adapt a collection to a reader for use with FeatureStore.setFeatures( reader ).
      Parameters:
      collection - Collection of SimpleFeature
      Returns:
      FeatureRedaer over the provided contents
      Throws:
      IOException - IOException if there is any problem reading the content.
    • 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<SimpleFeatureType,SimpleFeature> 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

    • 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<SimpleFeatureType,SimpleFeature> 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<SimpleFeatureType,SimpleFeature> 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<SimpleFeatureType,SimpleFeature> please make use of SimpleFeatureLocking if you possibly can.

      Since:
      2.7
    • list

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

      public static <F extends Feature> List<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 Feature> Iterator<F> iterator(FeatureIterator<F> featureIterator)
      Iteator wrapped around the provided FeatureIterator, implementing Closeable.
      Returns:
      Iterator wrapped around provided FeatureIterator, implements Closeable
      See Also:
    • 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 Feature> Collection<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

      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
    • 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
    • createSubType

      public static SimpleFeatureType createSubType(SimpleFeatureType featureType, String... properties) throws SchemaException
      Create a type limited to the named properties provided.
      Returns:
      type limited to the named properties provided
      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
    • createType

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

      Parameters:
      namespace - Typename namespace used to qualify the provided name
      name - Typename name, as qualified by namespace
      typeSpec - Definition of attributes, for details see createType(String, String)
      Throws:
      SchemaException
    • encodeType

      public static String encodeType(SimpleFeatureType featureType)
      Encode the provided featureType as a String suitable for use with createType(java.lang.String, java.lang.String).

      The format of this string acts as the "header" information for the PropertyDataStore implementations.

      Example:

      String header = "_="+DataUtilities.encodeType(schema);

      For more information please review the PropertyDataStore tutorials.

      Returns:
      String representation of featureType suitable for use with createType(java.lang.String, java.lang.String)
    • createFeature

      public static SimpleFeature createFeature(SimpleFeatureType featureType, String line)
      Reads in SimpleFeature that has been encoded into a line of text.

      Example:

       SimpleFeatureType featureType =
          DataUtilities.createType("FLAG","id:Integer|name:String|geom:Geometry:4326");
      
       SimpleFeature feature =
          DataUtilities.createFeature( featureType, "fid1=1|Jody Garnett\\nSteering Committee|POINT(1,2)" );
       
      This format is used by the PropertyDataStore tutorials. It amounts to:
      • Encoding of FeatureId followed by the attributes
      • Attributes are seperated using the bar character
      • Geometry is handled using WKTReader2
      • Support for common escaped characters
      • Multi-line support using escaped line-feed characters
        Returns:
        SimpleFeature defined by the provided line of text
      • encodeFeature

        public static String encodeFeature(SimpleFeature feature)
        Produce a String encoding of SimpleFeature for use with createFeature(org.geotools.api.feature.simple.SimpleFeatureType, java.lang.String).

        This method inlcudes the full featureId information.

        Parameters:
        feature - feature to encode, only SimpleFeature is supported at this time
        Returns:
        text encoding for use with createFeature(org.geotools.api.feature.simple.SimpleFeatureType, java.lang.String)
      • encodeFeature

        public static String encodeFeature(SimpleFeature feature, boolean includeFid)
        Produce a String encoding of SimpleFeature for use with createFeature(org.geotools.api.feature.simple.SimpleFeatureType, java.lang.String).

        This method inlcudes the full featureId information.

        Parameters:
        feature - feature to encode, only SimpleFeature is supported at this time
        includeFid - true to include the optional feature id
        Returns:
        text encoding for use with createFeature(org.geotools.api.feature.simple.SimpleFeatureType, java.lang.String)
      • parse

        public static SimpleFeature parse(SimpleFeatureType type, String fid, String... text) throws IllegalAttributeException
        Uses Converters to parse the provided text into the correct values to create a feature.
        Parameters:
        type - FeatureType
        fid - Feature ID for new feature
        text - Text representation of values
        Returns:
        newly created feature
        Throws:
        IllegalAttributeException
      • sortComparator

        public static Comparator<SimpleFeature> sortComparator(SortBy sortBy)
        Factory method to produce Comparator based on provided Query SortBy information.

        This method handles:

        Returns:
        Comparator suitable for use with Arrays.sort( SimpleFeature[], comparator )
      • mixQueries

        public static Query mixQueries(Query firstQuery, Query secondQuery, String handle)
        Takes two Queryobjects and produce a new one by mixing the restrictions of both of them.

        The policy to mix the queries components is the following:

        • typeName: type names MUST match (not checked if some or both queries equals to Query.ALL)
        • handle: you must provide one since no sensible choice can be done between the handles of both queries
        • maxFeatures: the lower of the two maxFeatures values will be used (most restrictive)
        • attributeNames: the attributes of both queries will be joined in a single set of attributes. IMPORTANT: only explicitly requested attributes will be joint, so, if the method retrieveAllProperties() of some of the queries returns true it does not means that all the properties will be joined. You must create the query with the names of the properties you want to load.
        • filter: the filters of both queries are or'ed, then simplified using SimplifiyingFilterVisitor
        • sort: if the second query has a sorting it's used for output, otherwise the one of the first is used
        • any other query property is ignored and no guarantees are made of their return values, so client code shall explicitly care of hints, startIndex, etc., if needed.
        Parameters:
        firstQuery - Query against this DataStore
        Returns:
        Query restricted to the limits of definitionQuery
        Throws:
        NullPointerException - if some of the queries is null
        IllegalArgumentException - if the type names of both queries do not match
      • simplifyFilter

        public static Query simplifyFilter(Query query)
        This method changes the query object by simplifying the filter using SimplifyingFilterVisitor
      • resolvePropertyNames

        public static Query resolvePropertyNames(Query query, SimpleFeatureType schema)
        This method changes the query object so that all propertyName references are resolved to simple attribute names against the schema of the feature source.

        For example, this method ensures that propertyName's such as "gml:name" are rewritten as simply "name". This method will not rewrite empty PropertyNames.

      • resolvePropertyNames

        public static Filter resolvePropertyNames(Filter filter, SimpleFeatureType schema)
        Transform provided filter; resolving property names
      • addMandatoryProperties

        public static List<PropertyName> addMandatoryProperties(SimpleFeatureType type, List<PropertyName> oldProps)
        Returns a list of properties of a simple feature type, including all properties from a given list, and all mandatory (minoccurs > 0) added.
        Parameters:
        type - feature type
        oldProps - given list of properties
        Returns:
        list of properties including all mandatory properties
      • count

        public static int count(FeatureIterator<?> iterator)
        Manually count the number of features from the provided FeatureIterator. This implementation is intended for FeatureCollection implementors and test case verification. Client code should always call FeatureCollection.size()
        Returns:
        number of featuers in feature collection
      • count

        public static int count(FeatureCollection<? extends FeatureType,? extends Feature> collection)
        Manually count the number of features in a feature collection using using FeatureCollection.features().

        This implementation is intended for FeatureCollection implementors and test case verification. Client code should always call FeatureCollection.size()

        Returns:
        number of featuers in feature collection
      • bounds

        public static ReferencedEnvelope bounds(FeatureIterator<?> iterator)
        Manually calculate the bounds from the provided FeatureIteator. This implementation is intended for FeatureCollection implementors and test case verification. Client code should always call FeatureCollection.getBounds().
      • bounds

        public static ReferencedEnvelope bounds(FeatureCollection<? extends FeatureType,? extends Feature> collection)
        Manually calculates the bounds of a feature collection using FeatureCollection.features().

        This implementation is intended for FeatureCollection implementors and test case verification. Client code should always call FeatureCollection.getBounds().

        Returns:
        bounds of features in feature collection
      • visit

        public static void visit(FeatureCollection<?,?> collection, FeatureVisitor visitor, ProgressListener progress) throws IOException
        Manually visit each feature using FeatureCollection.features().

        This method is intended to assist FeatureCollection implementors, and used to verify test-case results. Client code should always call FeatureCollection.accepts(FeatureVisitor, ProgressListener)

        Throws:
        IOException
      • checkFileReadable

        public static boolean checkFileReadable(File file, Logger logger)
        Checks that a File is a real file, exists and is readable.
        Parameters:
        file - the File instance to check. Must not be null.
        logger - an optional Logger (can be null) where to log detailed info about the file properties (path/readable/hidden/writable)
        Returns:
        true in case the file is a real file, exists and is readable; false otherwise.
      • checkDirectory

        public static File checkDirectory(File file) throws IllegalArgumentException
        Checks that the provided directory path refers to an existing/readable directory. Finally, return it as a normalized directory path (removing double and single dot path steps if any) followed by the separator char if missing ('/' On UNIX systems; '\\ on Microsoft Windows systems.
        Parameters:
        file - the input file. Must not be null.
        Returns:
        the re-formatted directory path.
        Throws:
        IllegalArgumentException - in case the specified path doesn't rely on a existing/readable directory.
      • canProcess

        public static boolean canProcess(Map<String,?> params, DataAccessFactory.Param... arrayParameters)
        Verifies a Map of parameters against the Param information. Primarily used by classes implementing DataAcessFactory.

        It will ensure that:

        • params is not null
        • Everything is of the correct type (or upcovertable to the correct type without Error)
        • Required Parameters are present
        Parameters:
        arrayParameters - Array of parameters returned by DataAccessFactory.getParametersInfo()
        Returns:
        true if params is in agreement with getParametersInfo, override for additional checks.
      • excludeFilters

        public static FilenameFilter excludeFilters(FilenameFilter inputFilter, FilenameFilter... filters)
        Returns a IOFileFilter obtained by excluding from the first input filter argument, the additional filter arguments.
        Parameters:
        inputFilter - the initial filter from which to exclude other ones.
        filters - additional filters to be excluded
        Returns:
        the updated IOFileFilter
      • includeFilters

        public static FilenameFilter includeFilters(FilenameFilter inputFilter, FilenameFilter... filters)
        Returns a IOFileFilter obtained by adding to the first input filter argument, the additional filter arguments.
        Parameters:
        inputFilter - the initial filter to which to add other ones.
        filters - additional filters to be included in the main filter.
        Returns:
        the updated IOFileFilter
      • templateFeature

        public static Feature templateFeature(FeatureType schema)
        Create a non-simple template feature from feature type schema
        Parameters:
        schema - the feature type
        Returns:
        a template feature
      • toConnectionParameters

        public static Map<String,Object> toConnectionParameters(Properties properties)
        Converts a Properties object into a Map suitable for usage for DataAccess or DataStore creation. The code assumes the properties do contain String keys, and may contain any kind of object as values.