org.geotools.data
Class DataUtilities

Object
  extended by 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 Summary
DataUtilities()
           
 
Method Summary
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.
static String[] attributeNames(Expression expression)
          Traverses the expression and returns any encountered property names.
static String[] attributeNames(Expression expression, SimpleFeatureType featureType)
          Traverses the expression and returns any encountered property names.
static String[] attributeNames(Filter filter)
          Traverses the filter and returns any encountered property names.
static String[] attributeNames(Filter filter, SimpleFeatureType featureType)
          Traverses the filter and returns any encountered property names.
static String[] attributeNames(SimpleFeatureType featureType)
          Retrieve the attributeNames defined by the featureType
static boolean attributesEqual(Object att, Object otherAtt)
          Used to compare if two values are equal.
static ReferencedEnvelope bounds(FeatureCollection<? extends FeatureType,? extends Feature> collection)
          Manually calculates the bounds of a feature collection using FeatureCollection.features().
static ReferencedEnvelope bounds(FeatureIterator<?> iterator)
          Manually calculate the bounds from the provided FeatureIteator.
static URL changeUrlExt(URL url, String postfix)
          Changes the ending (e.g. ".sld") of a URL
static File checkDirectory(File file)
          Checks that the provided directory path refers to an existing/readable directory.
static boolean checkFileReadable(File file, Logger logger)
          Checks that a File is a real file, exists and is readable.
static void close(Iterator<?> iterator)
          Checks if the provided iterator implements Closeable.
static DefaultFeatureCollection collection(FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)
          Copies the provided features into a FeatureCollection.
static SimpleFeatureCollection collection(FeatureReader<SimpleFeatureType,SimpleFeature> reader)
          Copies the provided reader into a FeatureCollection, reader will be closed.
static SimpleFeatureCollection collection(List<SimpleFeature> list)
          Copies the provided features into a FeatureCollection.
static SimpleFeatureCollection collection(SimpleFeature feature)
          Copies the provided features into a FeatureCollection.
static SimpleFeatureCollection collection(SimpleFeature[] features)
          Copies the provided features into a FeatureCollection.
static SimpleFeatureCollection collection(SimpleFeatureIterator reader)
          Copies the provided reader into a FeatureCollection, reader will be closed.
static
<F extends Feature>
Collection<F>
collectionCast(FeatureCollection<?,F> featureCollection)
          Used to quickly cast to a java.util.Collection.
static int compare(SimpleFeatureType typeA, SimpleFeatureType typeB)
          Compare attribute coverage between two feature types (allowing the identification of subTypes).
static int count(FeatureCollection<? extends FeatureType,? extends Feature> collection)
          Manually count the number of features in a feature collection using using FeatureCollection.features().
static int count(FeatureIterator<?> iterator)
          Manually count the number of features from the provided FeatureIterator.
static SimpleFeature createFeature(SimpleFeatureType featureType, String line)
          Reads in SimpleFeature that has been encoded into a line of text.
static SimpleFeatureType createSubType(SimpleFeatureType featureType, String[] properties)
          Create a type limited to the named properties provided.
static SimpleFeatureType createSubType(SimpleFeatureType featureType, String[] properties, CoordinateReferenceSystem override)
          Create a derived FeatureType
static SimpleFeatureType createSubType(SimpleFeatureType featureType, String[] properties, CoordinateReferenceSystem override, String typeName, URI namespace)
           
static SimpleFeatureType createType(String typeName, String typeSpec)
          Utility method for FeatureType construction.
static SimpleFeatureType createType(String namespace, String name, String typeSpec)
          Utility method for FeatureType construction.
static SimpleFeatureSource createView(DataStore store, Query query)
          Return a 'view' of the given DataStore constrained by a Query.
static Object defaultValue(AttributeDescriptor attributeType)
          Deprecated. Please AttributeDescriptor.getDefaultValue()
static Object defaultValue(Class type)
          Returns a non-null default value for the class that is passed in.
static Object[] defaultValues(SimpleFeatureType featureType)
          Produce a set of default values for the provided FeatureType
static Object[] defaultValues(SimpleFeatureType featureType, Object[] values)
          Create default values matching the provided feature type.
static Object duplicate(Object src)
          Performs a deep copy of the provided object.
static String encodeFeature(SimpleFeature feature)
          Produce a String encoding of SimpleFeature for use with createFeature(org.opengis.feature.simple.SimpleFeatureType, java.lang.String).
static String encodeFeature(SimpleFeature feature, boolean includeFid)
          Produce a String encoding of SimpleFeature for use with createFeature(org.opengis.feature.simple.SimpleFeatureType, java.lang.String).
static String encodeType(SimpleFeatureType featureType)
          Encode the provided featureType as a String suitable for use with createType(java.lang.String, java.lang.String).
static FilenameFilter excludeFilters(FilenameFilter inputFilter, FilenameFilter... filters)
          Returns a IOFileFilter obtained by excluding from the first input filter argument, the additional filter arguments.
static URL extendURL(URL base, String extension)
          Extends an URL.
static Set<String> fidSet(FeatureCollection<?,?> featureCollection)
          Copies the feature ids from each and every feature into a set.
static URL fileToURL(File file)
          A replacement for File.toURI().toURL().
static
<F extends Feature>
F
first(FeatureCollection<?,F> featureCollection)
          Obtain the first feature from the collection as an exemplar.
static URL getParentUrl(URL url)
          The function is supposed to be equivalent to File.getParent().
static FilenameFilter includeFilters(FilenameFilter inputFilter, FilenameFilter... filters)
          Returns a IOFileFilter obtained by adding to the first input filter argument, the additional filter arguments.
static boolean isMatch(AttributeDescriptor a, AttributeDescriptor b)
          Quickly check if two descriptors are at all compatible.
static
<F extends Feature>
Iterator<F>
iterator(FeatureIterator<F> featureIterator)
          Iteator wrapped around the provided FeatureIterator, implementing Closeable.
static
<F extends Feature>
List<F>
list(FeatureCollection<?,F> featureCollection)
          Copies the provided features into a List.
static
<F extends Feature>
List<F>
list(FeatureCollection<?,F> featureCollection, int maxFeatures)
          Copies the provided fetaures into a List.
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.
static SimpleFeature parse(SimpleFeatureType type, String fid, String[] text)
          Uses Converters to parse the provided text into the correct values to create a feature.
static Set<PropertyName> propertyNames(Expression expression)
          Traverses the expression and returns any encountered property names.
static Set<PropertyName> propertyNames(Expression expression, SimpleFeatureType featureType)
          Traverses the expression and returns any encountered property names.
static Set<PropertyName> propertyNames(Filter filter)
          Traverses the filter and returns any encountered property names.
static Set<PropertyName> propertyNames(Filter filter, SimpleFeatureType featureType)
          Traverses the filter and returns any encountered property names.
static FeatureReader<SimpleFeatureType,SimpleFeature> reader(Collection<SimpleFeature> collection)
          Adapt a collection to a reader for use with FeatureStore.setFeatures( reader ).
static FeatureReader<SimpleFeatureType,SimpleFeature> reader(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
          Adapt a collection to a reader for use with FeatureStore.setFeatures( reader ).
static FeatureReader<SimpleFeatureType,SimpleFeature> reader(SimpleFeature[] features)
          Creates a FeatureReader for testing.
static Filter resolvePropertyNames(Filter filter, SimpleFeatureType schema)
          Transform provided filter; resolving property names
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.
static SimpleFeature reType(SimpleFeatureType featureType, SimpleFeature feature)
          Creates duplicate of feature adjusted to the provided featureType.
static SimpleFeature reType(SimpleFeatureType featureType, SimpleFeature feature, boolean duplicate)
          Retypes the feature to match the provided featureType.
static SimpleFeatureCollection simple(FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)
          A safe cast to SimpleFeatureCollection; that will introduce a wrapper if it has to.
static SimpleFeatureLocking simple(FeatureLocking locking)
          A safe cast to SimpleFeatureLocking; that will introduce a wrapper if it has to.
static SimpleFeatureReader simple(FeatureReader<SimpleFeatureType,SimpleFeature> reader)
           
static SimpleFeatureSource simple(FeatureSource source)
          A safe cast to SimpleFeatureSource; that will introduce a wrapper if it has to.
static SimpleFeatureStore simple(FeatureStore store)
          A safe cast to SimpleFeatureStore; that will introduce a wrapper if it has to.
static SimpleFeatureType simple(FeatureType featureType)
          Go through FeatureType description and convert to a SimpleFeatureType.
static Comparator<SimpleFeature> sortComparator(SortBy sortBy)
          Factory method to produce Comparator based on provided Query SortBy information.
static SimpleFeatureSource source(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
          Wraps up the provided feature collection in as a SimpleFeatureSource.
static SimpleFeatureSource source(SimpleFeature[] featureArray)
          Wrap up an array of features as a FeatureSource.
static String spec(FeatureType featureType)
          Deprecated. Renamed to encodeType(org.opengis.feature.simple.SimpleFeatureType) for concistency with createType(java.lang.String, java.lang.String)
static SimpleFeature template(SimpleFeatureType featureType)
          Constructs an empty feature to use as a Template for new content.
static SimpleFeature template(SimpleFeatureType featureType, Object[] providedValues)
          Create a new feature from the provided values, using appropriate default values for any nulls provided.
static SimpleFeature template(SimpleFeatureType featureType, String featureID)
          Use the provided featureType to create an empty feature.
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.
static Feature templateFeature(FeatureType schema)
          Create a non-simple template feature from feature type schema
static File urlToFile(URL url)
          Takes a URL and converts it to a File.
static void visit(FeatureCollection<?,?> collection, FeatureVisitor visitor, ProgressListener progress)
          Manually visit each feature using FeatureCollection.features().
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataUtilities

public DataUtilities()
Method Detail

attributeNames

public static String[] attributeNames(SimpleFeatureType featureType)
Retrieve the attributeNames defined by the featureType

Parameters:
featureType -
Returns:
array of simple attribute names

fileToURL

public static URL fileToURL(File file)
A replacement for File.toURI().toURL().

The handling of file.toURL() is broken; the handling of file.toURI().toURL() is known to be broken on a few platforms like mac. We have the urlToFile( URL ) method that is able to untangle both these problems and we use it in the geotools library.

However occasionally we need to pick up a file and hand it to a third party library like EMF; this method performs a couple of sanity checks which we can use to prepare a good URL reference to a file in these situtations.

Parameters:
file -
Returns:
URL

urlToFile

public static File urlToFile(URL url)
Takes a URL and converts it to a File. The attempts to deal with Windows UNC format specific problems, specifically files located on network shares and different drives. If the URL.getAuthority() returns null or is empty, then only the url's path property is used to construct the file. Otherwise, the authority is prefixed before the path. It is assumed that url.getProtocol returns "file". Authority is the drive or network share the file is located on. Such as "C:", "E:", "\\fooServer"

Parameters:
url - a URL object that uses protocol "file"
Returns:
a File that corresponds to the URL's location

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).

The comparison results in a number with the following meaning:

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

Namespace is not considered in this opperations. You may still need to reType to get the correct namesapce, 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 beind compared
typeB - FeatureType being compared against

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.

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

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:

In the future this method may simply return a "wrapper" when duplicate is false.

Parameters:
featureType -
feature -
duplicate - True to perform duplicate(Object) on each attribute
Returns:
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:

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.

Parameters:
featureType -
featureID -
Returns:
Craeted feature

defaultValues

public static Object[] defaultValues(SimpleFeatureType featureType)
Produce a set of default values for the provided FeatureType

Parameters:
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.

Parameters:
featureType -
providedValues -
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:
featureType -
featureID -
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.

Parameters:
featureType -
values -
Returns:
set of default values
Throws:
ArrayIndexOutOfBoundsException - If the number of provided values does not match the featureType

defaultValue

public static Object defaultValue(AttributeDescriptor attributeType)
                           throws IllegalAttributeException
Deprecated. Please AttributeDescriptor.getDefaultValue()

Provides a defautlValue for attributeType.

Will return null if attributeType isNillable(), or attempt to use Reflection, or attributeType.parse( null )

Parameters:
attributeType -
Returns:
null for nillable attributeType, attempt at reflection
Throws:
IllegalAttributeException

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 any type but it does support:

Parameters:
type -
Returns:

reader

public static FeatureReader<SimpleFeatureType,SimpleFeature> reader(SimpleFeature[] features)
                                                             throws IOException
Creates a FeatureReader for testing.

Parameters:
features - Array of features
Returns:
FeatureReader spaning provided feature array
Throws:
IOException - If provided features Are null or empty
NoSuchElementException - DOCUMENT ME!

source

public static SimpleFeatureSource source(SimpleFeature[] featureArray)
Wrap up an array of features as a FeatureSource.

Parameters:
featureArray - Array of features
Returns:
FeatureSource
Throws:
IOException
RuntimeException

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)

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

reader

public static FeatureReader<SimpleFeatureType,SimpleFeature> reader(Collection<SimpleFeature> collection)
                                                             throws IOException
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

public static FeatureReader<SimpleFeatureType,SimpleFeature> reader(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
                                                             throws IOException
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:
SimpleFeatureCollection - 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.

Parameters:
featureCollection -
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?:

Parameters:
featureCollection - will be returned as a SimpleFeatureCollection and wrapped only if needed
Returns:
SimpleFeatureCollection
Since:
2.7

simple

public static SimpleFeatureReader simple(FeatureReader<SimpleFeatureType,SimpleFeature> reader)

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 Feature> List<F> list(FeatureCollection<?,F> featureCollection)
Copies the provided features into a List.

Parameters:
featureCollection -
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:
featureCollection -
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.

Parameters:
featureIterator -
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

Parameters:
featureCollection -
Returns:

collectionCast

public static <F extends Feature> Collection<F> collectionCast(FeatureCollection<?,F> featureCollection)
Used to quickly cast to a java.util.Collection.

Parameters:
featureCollection -
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(FeatureReader<SimpleFeatureType,SimpleFeature> 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

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 -
properties - - if null, every property of the feature type in input will be used
override -
Throws:
SchemaException

createSubType

public static SimpleFeatureType createSubType(SimpleFeatureType featureType,
                                              String[] properties,
                                              CoordinateReferenceSystem override,
                                              String typeName,
                                              URI namespace)
                                       throws SchemaException
Throws:
SchemaException

createSubType

public static SimpleFeatureType createSubType(SimpleFeatureType featureType,
                                              String[] properties)
                                       throws SchemaException
Create a type limited to the named properties provided.

Parameters:
featureType -
properties -
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:

  • Where hint is "hint1;hint2;...;hintN", in which "hintN" is one of:
    • nillable
    • srid=<#>
  • 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
  • Examples:

    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.

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

    spec

    public static String spec(FeatureType featureType)
    Deprecated. Renamed to encodeType(org.opengis.feature.simple.SimpleFeatureType) for concistency with createType(java.lang.String, java.lang.String)

    A "quick" String representation of a FeatureType.

    This string representation may be used with createType( name, spec ).

    Parameters:
    featureType - FeatureType to represent
    Returns:
    The string "specification" for the featureType

    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:

    encodeFeature

    public static String encodeFeature(SimpleFeature feature)
    Produce a String encoding of SimpleFeature for use with createFeature(org.opengis.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.opengis.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.opengis.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.opengis.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:

    Parameters:
    sortBy -
    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:

    Parameters:
    firstQuery - Query against this DataStore
    secondQuery - DOCUMENT ME!
    handle - DOCUMENT ME!
    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

    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".


    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
    propNames - given list of properties
    Returns:
    list of properties including all mandatory properties
    Throws:
    IOException

    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()

    Parameters:
    collection -
    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()

    Parameters:
    collection -
    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().

    Parameters:
    iterator -
    Returns:

    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().

    Parameters:
    collection -
    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)

    Parameters:
    collection -
    Throws:
    IOException

    changeUrlExt

    public static URL changeUrlExt(URL url,
                                   String postfix)
                            throws IllegalArgumentException
    Changes the ending (e.g. ".sld") of a URL

    Parameters:
    url - URL like file:/sds/a.bmp or http://www.some.org/foo/bar.shp
    postfix - New file extension for the URL without .
    Returns:
    A new URL with new extension.
    Throws:
    {@link - MalformedURLException} if the new URL can not be created.
    IllegalArgumentException

    getParentUrl

    public static URL getParentUrl(URL url)
                            throws MalformedURLException
    The function is supposed to be equivalent to File.getParent(). The URL is converted to a String, truncated to the last / and then recreated as a new URL.

    Throws:
    {@link - MalformedURLException} if the parent URL can not be created.
    MalformedURLException

    extendURL

    public static URL extendURL(URL base,
                                String extension)
                         throws MalformedURLException
    Extends an URL.

    Parameters:
    base - Has to be a URL pointing to a directory. If it doesn't end with a / it will be added automatically.
    extension - The part that will be added to the URL
    Throws:
    MalformedURLException - if the new URL can not be created.

    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:
    directoryPath - the input directory path. 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.

    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


    Copyright © 1996-2014 Geotools. All Rights Reserved.