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.
collection(org.geotools.api.feature.simple.SimpleFeature...)
methods: creating/converting aSimpleFeatureCollection
from a range of input.simple(org.geotools.feature.FeatureCollection<org.geotools.api.feature.simple.SimpleFeatureType, org.geotools.api.feature.simple.SimpleFeature>)
methods: adapting from generic Feature use to SimpleFeature. Used to convert to SimpleFeature, SimpleFeatureCollection,SimpleFeatureSourcelist(org.geotools.feature.FeatureCollection<?, F>)
to quickly copy features into a memory based listreader(org.geotools.api.feature.simple.SimpleFeature...)
methods to convert to FeatureReader#expression
setup a FeatureSource wrapper around the provided data
SimpleFeatureType and SimpleFeature encoding/decoding from String as used by the PropertyDataStore tutorials.
createType(java.lang.String, java.lang.String)
methods: to create a SimpleFeatureType from a one line text stringencodeType(org.geotools.api.feature.simple.SimpleFeatureType)
: text string representation of a SimpleFeaturerTypecreateFeature(org.geotools.api.feature.simple.SimpleFeatureType, java.lang.String)
: create a SimpleFeature from a one line text StringencodeFeature(org.geotools.api.feature.simple.SimpleFeature)
: encode a feature as a single line text string
Working with SimpleFeatureType (this class is immutable so we always have to make a modified copy):
createSubType(SimpleFeatureType, String[])
methods return a modified copy of an origional feature type. Used to cut down an exsiting feature type to reflect only the attributes requested when usingSimpleFeatureSource.getFeatures(Filter)
.compare(org.geotools.api.feature.simple.SimpleFeatureType, org.geotools.api.feature.simple.SimpleFeatureType)
andisMatch(AttributeDescriptor, AttributeDescriptor)
are used to check for types compatible withcreateSubType(org.geotools.api.feature.simple.SimpleFeatureType, java.lang.String[], org.geotools.api.referencing.crs.CoordinateReferenceSystem)
used to verify that feature values can be copied across
Manipulating individual features and data values:
reType(org.geotools.api.feature.simple.SimpleFeatureType, org.geotools.api.feature.simple.SimpleFeature)
generates a cut down version of an original feature in the same manners ascreateSubType(org.geotools.api.feature.simple.SimpleFeatureType, java.lang.String[], org.geotools.api.referencing.crs.CoordinateReferenceSystem)
template(org.geotools.api.feature.simple.SimpleFeatureType)
anddefaultValue(java.lang.Class)
methods which usesAttributeDescriptor.getDefaultValue()
when creating new empty featuresduplicate(Object)
used for deep copy of feature data
includeFilters(java.io.FilenameFilter, java.io.FilenameFilter...)
andexcludeFilters(java.io.FilenameFilter, java.io.FilenameFilter...)
work as a compoundFileFilter
makingFile.listFiles()
easier to usepropertyNames(org.geotools.api.filter.Filter, org.geotools.api.feature.simple.SimpleFeatureType)
,fidSet(org.geotools.feature.FeatureCollection<?, ?>)
,attributeNames(org.geotools.api.feature.simple.SimpleFeatureType)
methods are used to double check a provided query and ensure it can be correctly handed.sortComparator(org.geotools.api.filter.sort.SortBy)
,resolvePropertyNames(org.geotools.api.data.Query, org.geotools.api.feature.simple.SimpleFeatureType)
andmixQueries(org.geotools.api.data.Query, org.geotools.api.data.Query, java.lang.String)
are used to prep aQuery
prior to use
- Author:
- Jody Garnett, Refractions Research
-
-
Constructor Summary
Constructors Constructor Description DataUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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(SimpleFeatureType featureType)
Retrieve the attributeNames defined by the featureTypestatic 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 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 usingFeatureCollection.features()
.static ReferencedEnvelope
bounds(FeatureIterator<?> iterator)
Manually calculate the bounds from the provided FeatureIteator.static boolean
canProcess(Map<String,?> params, DataAccessFactory.Param... arrayParameters)
Verifies a Map of parameters against the Param information.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 aFile
is a real file, exists and is readable.static void
close(Iterator<?> iterator)
Checks if the provided iterator implementsCloseable
.static SimpleFeatureCollection
collection(List<SimpleFeature> list)
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(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 DefaultFeatureCollection
collection(FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)
Copies the provided features into a FeatureCollection.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).protected static int
compareInternal(SimpleFeatureType typeA, SimpleFeatureType typeB, boolean strict)
Compare attribute coverage between two feature types (allowing the identification of subTypes).static int
compareNames(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 usingFeatureCollection.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 FeatureTypestatic SimpleFeatureType
createSubType(SimpleFeatureType featureType, String[] properties, CoordinateReferenceSystem override, String typeName, URI namespace)
Create a derived FeatureTypestatic 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 givenDataStore
constrained by aQuery
.static SimpleFeatureSource
createView(SimpleFeatureSource source, Query query)
Return a 'view' of the givenFeatureSource
constrained by aQuery
.static DataStore
dataStore(SimpleFeatureSource source)
Adapt a single FeatureSource as a read-only DataStore.static DataStore
dataStore(SimpleFeatureCollection features)
Adapt a feature collection as a read-only DataStore.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 FeatureTypestatic 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 withcreateFeature(org.geotools.api.feature.simple.SimpleFeatureType, java.lang.String)
.static String
encodeFeature(SimpleFeature feature, boolean includeFid)
Produce a String encoding of SimpleFeature for use withcreateFeature(org.geotools.api.feature.simple.SimpleFeatureType, java.lang.String)
.static String
encodeType(SimpleFeatureType featureType)
Encode the provided featureType as a String suitable for use withcreateType(java.lang.String, java.lang.String)
.static FilenameFilter
excludeFilters(FilenameFilter inputFilter, FilenameFilter... filters)
Returns aIOFileFilter
obtained by excluding from the first input filter argument, the additional filter arguments.static Set<String>
fidSet(FeatureCollection<?,?> featureCollection)
Copies the feature ids from each and every feature into a set.static <F extends Feature>
Ffirst(FeatureCollection<?,F> featureCollection)
Obtain the first feature from the collection as an exemplar.static FilenameFilter
includeFilters(FilenameFilter inputFilter, FilenameFilter... filters)
Returns aIOFileFilter
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 boolean
isMatch(AttributeDescriptor a, AttributeDescriptor b, boolean strict)
Quickly check descriptors compatibility.static <F extends Feature>
Iterator<F>iterator(FeatureIterator<F> featureIterator)
Iteator wrapped around the provided FeatureIterator, implementingCloseable
.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 twoQuery
objects and produce a new one by mixing the restrictions of both of them.static SimpleFeature
parse(SimpleFeatureType type, String fid, String... text)
UsesConverters
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(SimpleFeature... features)
Creates a FeatureReaderfor testing. static SimpleFeatureReader
reader(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
Adapt a collection to a reader for use with FeatureStore.setFeatures( reader ).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 Filter
resolvePropertyNames(Filter filter, SimpleFeatureType schema)
Transform provided filter; resolving property namesstatic 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 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 SimpleFeatureCollection
simple(FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)
A safe cast to SimpleFeatureCollection; that will introduce a wrapper if it has to.static Query
simplifyFilter(Query query)
This method changes the query object by simplifying the filter using SimplifyingFilterVisitorstatic Comparator<SimpleFeature>
sortComparator(SortBy sortBy)
Factory method to produce Comparator based on provided Query SortBy information.static SimpleFeatureSource
source(SimpleFeature... featureArray)
Wrap up an array of features as a FeatureSource.static SimpleFeatureSource
source(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
Wraps up the provided feature collection in as a SimpleFeatureSource.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 schemastatic Map<String,Object>
toConnectionParameters(Properties properties)
static void
visit(FeatureCollection<?,?> collection, FeatureVisitor visitor, ProgressListener progress)
Manually visit each feature usingFeatureCollection.features()
.
-
-
-
Method Detail
-
attributeNames
public static String[] attributeNames(SimpleFeatureType featureType)
Retrieve the attributeNames defined by the featureType- Returns:
- array of simple attribute names
-
attributeNames
public static String[] attributeNames(Filter filter, SimpleFeatureType featureType)
Traverses the filter and returns any encountered property names.The feature type is supplied as contexts used to lookup expressions in cases where the attributeName does not match the actual name of the type.
-
propertyNames
public static Set<PropertyName> propertyNames(Filter filter, SimpleFeatureType featureType)
Traverses the filter and returns any encountered property names.The feature type is supplied as contexts used to lookup expressions in cases where the attributeName does not match the actual name of the type.
-
attributeNames
public static String[] attributeNames(Filter filter)
Traverses the filter and returns any encountered property names.
-
propertyNames
public static Set<PropertyName> propertyNames(Filter filter)
Traverses the filter and returns any encountered property names.
-
attributeNames
public static String[] attributeNames(Expression expression, SimpleFeatureType featureType)
Traverses the expression and returns any encountered property names.The feature type is supplied as contexts used to lookup expressions in cases where the attributeName does not match the actual name of the type.
-
propertyNames
public static Set<PropertyName> propertyNames(Expression expression, SimpleFeatureType featureType)
Traverses the expression and returns any encountered property names.The feature type is supplied as contexts used to lookup expressions in cases where the attributeName does not match the actual name of the type.
-
attributeNames
public static String[] attributeNames(Expression expression)
Traverses the expression and returns any encountered property names.
-
propertyNames
public static Set<PropertyName> propertyNames(Expression expression)
Traverses the expression and returns any encountered property names.
-
compare
public static int compare(SimpleFeatureType typeA, SimpleFeatureType typeB)
Compare attribute coverage between two feature types (allowing the identification of subTypes).Strict compatibility is assumed meaning that both the local name and java binding are compatible (see
compareInternal(SimpleFeatureType, SimpleFeatureType, boolean)
for more details.Namespace is not considered in this operations. You may still need to reType to get the correct namespace, or reorder.
Please note this method will not result in a stable sort if used in a
Comparator
as -1 is used to indicate incompatiblity (rather than simply "before").- Parameters:
typeA
- FeatureType being comparedtypeB
- 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 comparedtypeB
- 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
- theisMatch(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 comparedtypeB
- FeatureType being compared againststrict
- 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 compareb
- 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 compareb
- descriptor to comparestrict
- 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 requestedfeature
- 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
- Parameters:
duplicate
- True to performduplicate(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
- 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 ofAttributeDescriptor.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 FeatureReaderfor testing. - Parameters:
features
- Array of features- Returns:
- FeatureReader
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
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 nullIllegalArgumentException
- 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 givenDataStore
constrained by aQuery
.- Parameters:
store
- the data storequery
- the query- Returns:
- the constrained view
- Throws:
IOException
- if the data store cannot be accessedSchemaException
- 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 givenFeatureSource
constrained by aQuery
.- Parameters:
source
- feature sourcequery
- the query- Returns:
- the constrained view
- Throws:
IOException
- if the data store cannot be accessedSchemaException
- 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
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 SimpleFeatureReader 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:
featureCollection
- the features to add to a new feature collection.- Returns:
- FeatureCollection
-
close
public static void close(Iterator<?> iterator)
Checks if the provided iterator implementsCloseable
.Any problems are logged at
Level.FINE
.
-
first
public static <F extends Feature> F first(FeatureCollection<?,F> featureCollection)
Obtain the first feature from the collection as an exemplar.- Returns:
- first feature from the featureCollection
-
simple
public static SimpleFeatureCollection simple(FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)
A safe cast to SimpleFeatureCollection; that will introduce a wrapper if it has to.Please keep the use of this class to a minimum; if you are expecting a FeatureCollection
please make use of SimpleFeatureCollection if you possibly can. So when are you stuck using this class?:
- Offering backwards compatible constructors for legacy code prior to 2.7
- implementing FeatureStore.addFeatures(...) since we cannot type narrow parameters
- Parameters:
featureCollection
- will be returned as a SimpleFeatureCollection and wrapped only if needed- Returns:
- SimpleFeatureCollection
- Since:
- 2.7
-
simple
public static 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.- 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, implementingCloseable
.- Returns:
- Iterator wrapped around provided FeatureIterator, implements Closeable
- See Also:
close(Iterator)
-
fidSet
public static Set<String> fidSet(FeatureCollection<?,?> featureCollection)
Copies the feature ids from each and every feature into a set.This method can be slurp an in memory record of the contents of a
-
collectionCast
public static <F extends 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
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:
- Object.equals( Object )
- Geometry.equals( Geometry ) - similar to
Geometry.equalsExact(Geometry)
- Parameters:
att
- Attribute valueotherAtt
- 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 usedoverride
- 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 usedoverride
- Intended CoordinateReferenceSystem, if null original will be usedtypeName
- Type name overridenamespace
- 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).typeNametypeSpec
- 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 namename
- Typename name, as qualified by namespacetypeSpec
- Definition of attributes, for details seecreateType(String, String)
- Throws:
SchemaException
-
encodeType
public static String encodeType(SimpleFeatureType featureType)
Encode the provided featureType as a String suitable for use withcreateType(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 withcreateFeature(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 withcreateFeature(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 timeincludeFid
- 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
UsesConverters
to parse the provided text into the correct values to create a feature.- Parameters:
type
- FeatureTypefid
- Feature ID for new featuretext
- 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:
SortBy.NATURAL_ORDER
: As sorting by FeatureID
- Returns:
- Comparator suitable for use with Arrays.sort( SimpleFeature[], comparator )
-
mixQueries
public static Query mixQueries(Query firstQuery, Query secondQuery, String handle)
Takes twoQuery
objects 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 returnstrue
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 nullIllegalArgumentException
- if the type names of both queries do not match
- typeName: type names MUST match (not checked if some or both queries equals to
-
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 typeoldProps
- 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 callFeatureCollection.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 usingFeatureCollection.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 callFeatureCollection.getBounds()
.
-
bounds
public static ReferencedEnvelope bounds(FeatureCollection<? extends FeatureType,? extends Feature> collection)
Manually calculates the bounds of a feature collection usingFeatureCollection.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 usingFeatureCollection.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 aFile
is a real file, exists and is readable.
-
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 aIOFileFilter
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 aIOFileFilter
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 aProperties
object into a Map suitable for usage forDataAccess
orDataStore
creation. The code assumes the properties do containString
keys, and may contain any kind of object as values.
-
-