org.geotools.data
Class DataUtilities

Object
  extended by DataUtilities

public class DataUtilities
extends Object

Utility functions for use when implementing working with data classes.

TODO: Move FeatureType manipulation to feature package

Author:
Jody Garnett, Refractions Research
Module:
modules/library/main (gt-main.jar)

Constructor Summary
DataUtilities()
           
 
Method Summary
static String[] attributeNames(Expression expression)
          Deprecated. use #attributeNames(Expression, FeatureType)/
static String[] attributeNames(Expression expression, SimpleFeatureType featureType)
          Traverses the expression and returns any encoutered property names.
static String[] attributeNames(Filter filter)
          Deprecated. use #attributeNames(Filter, FeatureType)/
static String[] attributeNames(Filter filter, SimpleFeatureType featureType)
          Traverses the filter and returns any encoutered property names.
static String[] attributeNames(SimpleFeatureType featureType)
          DOCUMENT ME!
static boolean attributesEqual(Object att, Object otherAtt)
          DOCUMENT ME!
static Envelope bounds(FeatureCollection<? extends FeatureType,? extends Feature> collection)
          Manually calculates the bounds of a feature collection.
static URL changeUrlExt(URL url, String postfix)
          Changes the ending (e.g. ".sld") of a URL
static DefaultFeatureCollection collection(FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)
          Copies the provided features into a FeatureCollection.
static FeatureCollection<SimpleFeatureType,SimpleFeature> collection(FeatureIterator<SimpleFeature> reader)
          Copies the provided reader into a FeatureCollection, reader will be closed.
static FeatureCollection<SimpleFeatureType,SimpleFeature> collection(FeatureReader<SimpleFeatureType,SimpleFeature> reader)
          Copies the provided reader into a FeatureCollection, reader will be closed.
static FeatureCollection<SimpleFeatureType,SimpleFeature> collection(List<SimpleFeature> list)
          Copies the provided features into a FeatureCollection.
static FeatureCollection<SimpleFeatureType,SimpleFeature> collection(SimpleFeature feature)
          Copies the provided features into a FeatureCollection.
static FeatureCollection<SimpleFeatureType,SimpleFeature> collection(SimpleFeature[] features)
          Copies the provided features into a FeatureCollection.
static int compare(SimpleFeatureType typeA, SimpleFeatureType typeB)
          Compare operation for FeatureType.
static SimpleFeatureType createSubType(SimpleFeatureType featureType, String[] properties)
          DOCUMENT ME!
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 identification, String typeSpec)
          Utility method for FeatureType construction.
static SimpleFeatureType createType(String namespace, String typeName, String typeSpec)
          Utility method for FeatureType construction.
static Object defaultValue(AttributeDescriptor attributeType)
          Provides a defautlValue for attributeType.
static Object defaultValue(Class type)
          Returns a non-null default value for the class that is passed in.
static Object[] defaultValues(SimpleFeatureType featureType)
          DOCUMENT ME!
static Object[] defaultValues(SimpleFeatureType featureType, Object[] values)
          DOCUMENT ME!
static Object duplicate(Object src)
           
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 URL getParentUrl(URL url)
          The function is supposed to be equivalent to File.getParent().
static boolean isMatch(AttributeDescriptor a, AttributeDescriptor b)
          DOCUMENT ME!
static List<SimpleFeature> list(FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)
          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)
          DOCUMENT ME!
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 FeatureCollection<SimpleFeatureType,SimpleFeature> results(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
          Returns collection if non empty.
static FeatureCollection<SimpleFeatureType,SimpleFeature> results(SimpleFeature[] featureArray)
           
static SimpleFeature reType(SimpleFeatureType featureType, SimpleFeature feature)
          Creates duplicate of feature adjusted to the provided featureType.
static FeatureSource<SimpleFeatureType,SimpleFeature> source(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
          DOCUMENT ME!
static FeatureSource<SimpleFeatureType,SimpleFeature> source(SimpleFeature[] featureArray)
          DOCUMENT ME!
static String spec(FeatureType featureType)
          A "quick" String representation of a FeatureType.
static SimpleFeature template(SimpleFeatureType featureType)
          Constructs an empty feature to use as a Template for new content.
static SimpleFeature template(SimpleFeatureType featureType, Object[] atts)
          DOCUMENT ME!
static SimpleFeature template(SimpleFeatureType featureType, String featureID)
          DOCUMENT ME!
static SimpleFeature template(SimpleFeatureType featureType, String featureID, Object[] atts)
          DOCUMENT ME!
static File urlToFile(URL url)
          Takes a URL and converts it to a File.
 
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)
DOCUMENT ME!

Parameters:
featureType - DOCUMENT ME!
Returns:
DOCUMENT ME!

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 encoutered property names.

The feautre 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)
Deprecated. use #attributeNames(Filter, FeatureType)/

Traverses the filter and returns any encoutered property names.


attributeNames

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

The feautre 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)
Deprecated. use #attributeNames(Expression, FeatureType)/

Traverses the expression and returns any encoutered property names.


compare

public static int compare(SimpleFeatureType typeA,
                          SimpleFeatureType typeB)
Compare operation for FeatureType.

Results in:

Comparison is based on AttributeTypes, an IOException is thrown if the AttributeTypes are not compatiable.

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

Parameters:
typeA - FeatureType beind compared
typeB - FeatureType being compared against

isMatch

public static boolean isMatch(AttributeDescriptor a,
                              AttributeDescriptor b)
DOCUMENT ME!

Parameters:
a - DOCUMENT ME!
b - DOCUMENT ME!
Returns:
DOCUMENT ME!

reType

public static SimpleFeature reType(SimpleFeatureType featureType,
                                   SimpleFeature feature)
                            throws IllegalAttributeException
Creates duplicate of feature adjusted to the provided featureType.

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

duplicate

public static Object duplicate(Object src)

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 - if we could not create featureType instance with acceptable default values

template

public static SimpleFeature template(SimpleFeatureType featureType,
                                     String featureID)
                              throws IllegalAttributeException
DOCUMENT ME!

Parameters:
featureType - DOCUMENT ME!
featureID - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalAttributeException - DOCUMENT ME!

defaultValues

public static Object[] defaultValues(SimpleFeatureType featureType)
                              throws IllegalAttributeException
DOCUMENT ME!

Parameters:
featureType - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalAttributeException - DOCUMENT ME!

template

public static SimpleFeature template(SimpleFeatureType featureType,
                                     Object[] atts)
                              throws IllegalAttributeException
DOCUMENT ME!

Parameters:
featureType - DOCUMENT ME!
atts - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalAttributeException - DOCUMENT ME!

template

public static SimpleFeature template(SimpleFeatureType featureType,
                                     String featureID,
                                     Object[] atts)
                              throws IllegalAttributeException
DOCUMENT ME!

Parameters:
featureType - DOCUMENT ME!
featureID - DOCUMENT ME!
atts - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalAttributeException - DOCUMENT ME!

defaultValues

public static Object[] defaultValues(SimpleFeatureType featureType,
                                     Object[] values)
                              throws IllegalAttributeException
DOCUMENT ME!

Parameters:
featureType - DOCUMENT ME!
values - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalAttributeException - DOCUMENT ME!
ArrayIndexOutOfBoundsException - DOCUMENT ME!

defaultValue

public static Object defaultValue(AttributeDescriptor attributeType)
                           throws IllegalAttributeException
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 - If value cannot be constructed for attribtueType

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 FeatureSource<SimpleFeatureType,SimpleFeature> source(SimpleFeature[] featureArray)
DOCUMENT ME!

Parameters:
featureArray - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IOException - DOCUMENT ME!
RuntimeException - DOCUMENT ME!

source

public static FeatureSource<SimpleFeatureType,SimpleFeature> source(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
DOCUMENT ME!

Parameters:
collection - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
NullPointerException - DOCUMENT ME!
RuntimeException - DOCUMENT ME!

results

public static FeatureCollection<SimpleFeatureType,SimpleFeature> results(SimpleFeature[] featureArray)

results

public static FeatureCollection<SimpleFeatureType,SimpleFeature> results(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
Returns collection if non empty.

Parameters:
collection -
Returns:
provided collection
Throws:
IOException - Raised if collection was empty

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 FeatureCollection<SimpleFeatureType,SimpleFeature> 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 FeatureCollection into memory.

Parameters:
FeatureCollection - SimpleFeature> the features to add to a new feature collection.
Returns:
FeatureCollection

list

public static List<SimpleFeature> list(FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)
Copies the provided fetaures into a List.

Parameters:
featureCollection -
Returns:
List of features copied into memory

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:

collection

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

Often used when gathering a FeatureCollection into memory.

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

collection

public static FeatureCollection<SimpleFeatureType,SimpleFeature> 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 FeatureCollection<SimpleFeatureType,SimpleFeature> 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 FeatureCollection<SimpleFeatureType,SimpleFeature> collection(FeatureIterator<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

attributesEqual

public static boolean attributesEqual(Object att,
                                      Object otherAtt)
DOCUMENT ME!

Parameters:
att - DOCUMENT ME!
otherAtt - DOCUMENT ME!
Returns:
DOCUMENT ME!

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
DOCUMENT ME!

Parameters:
featureType - DOCUMENT ME!
properties - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
SchemaException - DOCUMENT ME!

createType

public static SimpleFeatureType createType(String identification,
                                           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.

You may indicate the default Geometry with an astrix: "*geom:Geometry". You may also indicate the srid (used to look up a EPSG code).

Examples:

  • name:"",age:0,geom:Geometry,centroid:Point,url:java.io.URL"
  • id:String,polygonProperty:Polygon:srid=32615

Parameters:
identification - identification of FeatureType: (namesapce).typeName
typeSpec - Specification for FeatureType
Throws:
SchemaException

createType

public static SimpleFeatureType createType(String namespace,
                                           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.

You may indicate the default Geometry with an astrix: "*geom:Geometry". You may also indicate the srid (used to look up a EPSG code).

Examples:

  • name:"",age:0,geom:Geometry,centroid:Point,url:java.io.URL"
  • id:String,polygonProperty:Polygon:srid=32615

Parameters:
identification - identification of FeatureType: (namesapce).typeName
typeSpec - Specification for FeatureType
Throws:
SchemaException

parse

public static SimpleFeature parse(SimpleFeatureType type,
                                  String fid,
                                  String[] text)
                           throws IllegalAttributeException
DOCUMENT ME!

Parameters:
type - DOCUMENT ME!
fid - DOCUMENT ME!
text - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalAttributeException - DOCUMENT ME!

spec

public static String spec(FeatureType featureType)
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

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 filtets of both queries are or'ed
  • 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
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

bounds

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

Parameters:
collection -
Returns:

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.


Copyright © 1996-2009 Geotools. All Rights Reserved.