Class SimpleFeatureTypeBuilder
Simple Usage:
//create the builder
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
//set global state
builder.setName( "testType" );
builder.setNamespaceURI( "http://www.geotools.org/" );
builder.setSRS( "EPSG:4326" );
//add attributes
builder.add( "intProperty", Integer.class );
builder.add( "stringProperty", String.class );
builder.add( "pointProperty", Point.class );
//add attribute setting per attribute state
builder.minOccurs(0).maxOccurs(2).nillable(false).add("doubleProperty",Double.class);
//build the type
SimpleFeatureType featureType = builder.buildFeatureType();
This builder builds type by maintaining state. Two types of state are maintained: Global Type State and Per
Attribute State. Methods which set global state are named
set<property>()
. Methods which set per attribute state are named <property>()
. Furthermore calls to per attribute
Global state is reset after a call to buildFeatureType()
. Per attribute state is reset after a call to
add(java.lang.String, java.lang.Class<?>)
.
A default geometry for the feature type can be specified explictly via setDefaultGeometry(String)
.
However if one is not set the first geometric attribute (GeometryType
) added will be resulting default. So if
only specifying a single geometry for the type there is no need to call the method. However if specifying multiple
geometries then it is good practice to specify the name of the default geometry type. For instance:
builder.add( "pointProperty", Point.class );
builder.add( "lineProperty", LineString.class );
builder.add( "polygonProperty", Polygon.class );
builder.setDefaultGeometry( "lineProperty" );
- Author:
- Justin Deolivera, Jody Garnett
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AttributeTypeBuilder
attribute builderprotected List<AttributeDescriptor>
List of attributes.protected Map<Class<?>,
AttributeType> Map of java class bound to properties types.protected CoordinateReferenceSystem
default coordinate reference system of the typeprotected boolean
protected String
Name of the default geometry to useprotected InternationalString
Description of type.protected FeatureTypeFactory
factoriesprotected boolean
flag controlling if the type is abstract.protected String
Naming: local nameAdditional restrictions on the type.protected SimpleFeatureType
the parent type.protected String
Naming: uri indicating scope -
Constructor Summary
ConstructorsConstructorDescriptionConstructs the builder.Constructs the builder specifying the factory for creating feature and feature collection types. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int index, AttributeDescriptor descriptor) Adds a descriptor to the builder by index.void
Adds a new attribute w/ provided name and class.void
Adds a new geometric attribute w/ provided name, class, and spatial reference system identifiervoid
Adds a new geometric attribute w/ provided name, class, and spatial reference system identifiervoid
add
(String name, Class<?> binding, CoordinateReferenceSystem crs) Adds a new geometric attribute w/ provided name, class, and coordinate reference system.void
add
(AttributeDescriptor descriptor) Adds a descriptor directly to the builder.void
addAll
(List<AttributeDescriptor> descriptors) Adds a list of descriptors directly to the builder.void
addAll
(AttributeDescriptor... descriptors) Adds an array of descriptors directly to the builder.void
addBinding
(AttributeType type) Specifies an attribute type binding.void
addBindings
(Schema schema) Specifies a number of attribute type bindings.protected List<AttributeDescriptor>
Accessor for attributes (will create attributes list if needed)protected Map<Class<?>,
AttributeType> bindings()
Accessor for bindings (will create binding map if needed).Builds a feature type from compiled state.static SimpleFeatureType
copy
(SimpleFeatureType original) Copies a feature type.Sets the crs of the next attribute added to the feature type.protected CoordinateReferenceSystem
Decodes a srs, supplying a useful error message if there is a problem.defaultValue
(Object defaultValue) Sets the default value of the next attribute added to the feature type.description
(String description) Sets the description of the next attribute added to the feature type.descriptor
(AttributeDescriptor descriptor) Sets all the attribute specific state from a single descriptor.get
(int index) Gets an AttributeBuilder configured using the descriptor at the provided index.getBinding
(Class<?> binding) Looks up an attribute type which has been bound to a class.getCRS()
The fallback coordinate reference system that will be applied to any geometric attributes added to the type without their own coordinate reference system specified.The name of the default geometry attribute of the built type.The description of the built type.The factory used to create feature and feature collection types.getName()
The name of the built type.The namespace uri of the built type.The super type of the built type.protected void
init()
Clears the running list of attributes.void
init
(SimpleFeatureType type) Initializes the builder with state from a pre-existing feature type.boolean
The flag controlling if the resulting type is abstract.length
(int length) Sets a restriction on the field length of the next attribute added to the feature type.maxOccurs
(int maxOccurs) Sets the maxOccurs of the next attribute added to the feature type.minOccurs
(int minOccurs) Sets the minOccurs of the next attribute added to the feature type.protected Name
name()
Naming: Accessor which returns type name as follows: IftypeName
has been set, its value is returned.protected List
newList()
Creates a new list instance, this default impelementation returnsArrayList
.protected List
Creates a new list which is the same type as the provided list.protected Map
newMap()
Creates a new map instance, this default implementation returnsHashMap
protected Set
newSet()
Creates a new set instance, this default implementation returnsHashSet
.nillable
(boolean isNillable) Sets the nullability of the next attribute added to the feature type.Sets a restriction on the possible field values of the next attribute added to the feature type.Sets a restriction on the possible field values of the next attribute added to the feature type.Removes an attribute from the builderprotected void
reset()
Completely resets all builder state.restriction
(Filter filter) Adds a restriction to the next attribute added to the feature type.Accessor for restrictions (will create restrictions list if needed).restrictions
(List<Filter> filters) Adds a collection of restrictions to the next attribute added to thestatic SimpleFeatureType
retype
(SimpleFeatureType original, String... attributes) Create a SimpleFeatureType containing just the attribute descriptors indicated.static SimpleFeatureType
retype
(SimpleFeatureType original, List<String> attributes) Create a SimpleFeatureType containing just the attribute descriptors indicated.static SimpleFeatureType
retype
(SimpleFeatureType original, Query query) Create a SimpleFeatureType with the parameters and coordinate reference system of the query.static SimpleFeatureType
retype
(SimpleFeatureType original, CoordinateReferenceSystem crs) Create a SimpleFeatureType with the same content; just updating the geometry attribute to match the provided coordinate reference system.void
set
(int index, AttributeDescriptor descriptor) Replace the descriptor at the provided index.void
set
(String attributeName, AttributeDescriptor descriptor) Replace the descriptor at the provided index.void
set
(String attributeName, AttributeTypeBuilder attributeBuilder) Replace the descriptor at the provided index.void
set
(AttributeDescriptor descriptor) Replace the descriptor at the provided index.void
setAbstract
(boolean isAbstract) Sets the flag controlling if the resulting type is abstract.void
setAttributes
(List<AttributeDescriptor> attributes) Directly sets the list of attributes.void
setAttributes
(AttributeDescriptor... attributes) Directly sets the list of attributes.void
setBindings
(Schema schema) Specifies a number of attribute type bindings clearing out all existing bindings.void
Sets the coordinate reference system of the next attribute being added.void
setDefaultGeometry
(String defaultGeometryName) Sets the name of the default geometry attribute of the built type.void
setDescription
(InternationalString description) Sets the description of the built type.void
setFeatureTypeFactory
(FeatureTypeFactory factory) Sets the factory used to create feature and feature collection types.void
Sets the name of the built type.void
Sets the local name and namespace uri of the built type.void
setNamespaceURI
(String namespaceURI) Set the namespace uri of the built type.void
setNamespaceURI
(URI namespaceURI) void
Sets the coordinate reference system of the next attribute being added by specifying its srs.void
setSuperType
(SimpleFeatureType superType) Sets the super type of the built type.Sets the srid of the next attribute added to the feature type.Sets the srs of the next attribute added to the feature type.Sets user data for the next attribute added to the feature type.
-
Field Details
-
factory
factories -
bindings
Map of java class bound to properties types. -
local
Naming: local name -
uri
Naming: uri indicating scope -
description
Description of type. -
attributes
List of attributes. -
restrictions
Additional restrictions on the type. -
defaultGeometry
Name of the default geometry to use -
defaultCrsSet
protected boolean defaultCrsSet -
defaultCrs
default coordinate reference system of the type -
isAbstract
protected boolean isAbstractflag controlling if the type is abstract. -
superType
the parent type. -
attributeBuilder
attribute builder
-
-
Constructor Details
-
SimpleFeatureTypeBuilder
public SimpleFeatureTypeBuilder()Constructs the builder. -
SimpleFeatureTypeBuilder
Constructs the builder specifying the factory for creating feature and feature collection types.
-
-
Method Details
-
setFeatureTypeFactory
Sets the factory used to create feature and feature collection types. -
getFeatureTypeFactory
The factory used to create feature and feature collection types. -
init
Initializes the builder with state from a pre-existing feature type. -
init
protected void init()Clears the running list of attributes. -
reset
protected void reset()Completely resets all builder state. -
setNamespaceURI
Set the namespace uri of the built type. -
setNamespaceURI
-
getNamespaceURI
The namespace uri of the built type. -
setName
Sets the name of the built type. -
getName
The name of the built type. -
setName
Sets the local name and namespace uri of the built type. -
setDescription
Sets the description of the built type. -
getDescription
The description of the built type. -
setDefaultGeometry
Sets the name of the default geometry attribute of the built type. -
getDefaultGeometry
The name of the default geometry attribute of the built type. -
setCRS
Sets the coordinate reference system of the next attribute being added.The supplied coordinate reference is a "default" only used if geometric attributes are later added to the type without specifying their coordinate reference system.
You must call this method prior to calling add for it to function.
Example:
builder.setCRS( DefaultGeographicCRS.EGS84 ); builder.add( "geom", Polygon.class );
-
getCRS
The fallback coordinate reference system that will be applied to any geometric attributes added to the type without their own coordinate reference system specified. -
setSRS
Sets the coordinate reference system of the next attribute being added by specifying its srs.- Throws:
IllegalArgumentException
- When the srs specified can be decored into a crs.
-
setAbstract
public void setAbstract(boolean isAbstract) Sets the flag controlling if the resulting type is abstract. -
isAbstract
public boolean isAbstract()The flag controlling if the resulting type is abstract. -
setSuperType
Sets the super type of the built type. -
getSuperType
The super type of the built type. -
addBinding
Specifies an attribute type binding.This method is used to associate an attribute type with a java class. The class is retreived from
type.getBinding()
. When theadd(String, Class)
method is used to add an attribute to the type being built, this binding is used to locate the attribute type.- Parameters:
type
- The attribute type.
-
addBindings
Specifies a number of attribute type bindings.- Parameters:
schema
- The schema containing the attribute types.
-
setBindings
Specifies a number of attribute type bindings clearing out all existing bindings.- Parameters:
schema
- The schema contianing attribute types.
-
getBinding
Looks up an attribute type which has been bound to a class.- Parameters:
binding
- The class.- Returns:
- AttributeType The bound attribute type.
-
minOccurs
Sets the minOccurs of the next attribute added to the feature type.This value is reset after a call to
add(String, Class)
-
maxOccurs
Sets the maxOccurs of the next attribute added to the feature type.This value is reset after a call to
add(String, Class)
-
nillable
Sets the nullability of the next attribute added to the feature type.This value is reset after a call to
add(String, Class)
-
length
Sets a restriction on the field length of the next attribute added to the feature type.This method is the same as adding a restriction based on length( value ) < length This value is reset after a call to
add(String, Class)
-
options
Sets a restriction on the possible field values of the next attribute added to the feature type.This method is the same as adding a restriction based on value in (option1, option2, ...}. This restriction is reset after a call to
add(String, Class)
-
options
Sets a restriction on the possible field values of the next attribute added to the feature type.This method is the same as adding a restriction based on value in (option1, option2, ...}. This restriction is reset after a call to
add(String, Class)
-
restriction
Adds a restriction to the next attribute added to the feature type.This value is reset after a call to
add(String, Class)
-
restrictions
Adds a collection of restrictions to the next attribute added to theThis value is reset after a call to
add(String, Class)
-
description
Sets the description of the next attribute added to the feature type.This value is reset after a call to
add(String, Class)
-
defaultValue
Sets the default value of the next attribute added to the feature type.This value is reset after a call to
add(String, Class)
-
crs
Sets the crs of the next attribute added to the feature type.This only applies if the attribute added is geometric. Example:
builder.crs( DefaultGeographicCRS.WGS84 ).add( "geom", Polygon.class )
This value is reset after a call to
add(String, Class)
-
srs
Sets the srs of the next attribute added to the feature type.The srs parameter is the id of a spatial reference system, for example: "epsg:4326".
This only applies if the attribute added is geometric.
This value is reset after a call to
add(String, Class)
- Parameters:
srs
- The spatial reference system.
-
srid
Sets the srid of the next attribute added to the feature type.The srid parameter is the epsg code of a spatial reference system, for example: "4326".
This only applies if the attribute added is geometric.
This value is reset after a call to
add(String, Class)
- Parameters:
srid
- The id of a spatial reference system.
-
userData
Sets user data for the next attribute added to the feature type.This value is reset after a call to
add(String, Class)
- Parameters:
key
- The key of the user data.value
- The value of the user data.
-
descriptor
Sets all the attribute specific state from a single descriptor.This method is convenience for:
builder.minOccurs( descriptor.getMinOccurs() ).maxOccurs( descriptor.getMaxOccurs() ) .nillable( descriptor.isNillable() )...
-
add
Adds a new attribute w/ provided name and class.The provided class is used to locate an attribute type binding previously specified by
addBinding(AttributeType)
,addBindings(Schema)
, orsetBindings(Schema)
.If not such binding exists then an attribute type is created on the fly.
- Parameters:
name
- The name of the attribute.binding
- The class the attribute is bound to.
-
add
Adds a descriptor directly to the builder.Use of this method is discouraged. Consider using
add(String, Class)
. -
remove
Removes an attribute from the builder- Parameters:
attributeName
- the name of the AttributeDescriptor to remove- Returns:
- the AttributeDescriptor with the name attributeName
- Throws:
IllegalArgumentException
- if there is no AttributeDescriptor with the name attributeName
-
add
Adds a descriptor to the builder by index.Use of this method is discouraged. Consider using
add(String, Class)
. -
addAll
Adds a list of descriptors directly to the builder.Use of this method is discouraged. Consider using
add(String, Class)
. -
addAll
Adds an array of descriptors directly to the builder.Use of this method is discouraged. Consider using
add(String, Class)
. -
add
Adds a new geometric attribute w/ provided name, class, and coordinate reference system.The crs parameter may be
null
.- Parameters:
name
- The name of the attribute.binding
- The class that the attribute is bound to.crs
- The crs of of the geometry, may benull
.
-
add
Adds a new geometric attribute w/ provided name, class, and spatial reference system identifierThe srs parameter may be
null
.- Parameters:
name
- The name of the attribute.binding
- The class that the attribute is bound to.srs
- The srs of of the geometry, may benull
.
-
add
Adds a new geometric attribute w/ provided name, class, and spatial reference system identifierThe srid parameter may be
null
.- Parameters:
name
- The name of the attribute.binding
- The class that the attribute is bound to.srid
- The srid of of the geometry, may benull
.
-
get
Gets an AttributeBuilder configured using the descriptor at the provided index.- Parameters:
index
- attribute index- Returns:
- attribute builder configured with descriptor
-
get
-
set
Replace the descriptor at the provided index. -
set
Replace the descriptor at the provided index. -
set
Replace the descriptor at the provided index. -
set
Replace the descriptor at the provided index. -
setAttributes
Directly sets the list of attributes.- Parameters:
attributes
- the new list of attributes, or null to reset the list
-
setAttributes
Directly sets the list of attributes.- Parameters:
attributes
- the new list of attributes, or null to reset the list
-
buildFeatureType
Builds a feature type from compiled state.After the type is built the running list of attributes is cleared.
- Returns:
- The built feature type.
-
newSet
Creates a new set instance, this default implementation returnsHashSet
. -
newList
Creates a new list instance, this default impelementation returnsArrayList
. -
newMap
Creates a new map instance, this default implementation returnsHashMap
-
newList
Creates a new list which is the same type as the provided list.If the new copy can not be created reflectively..
newList()
is returned. -
name
Naming: Accessor which returns type name as follows:- If
typeName
has been set, its value is returned. - If
name
has been set, it +namespaceURI
are returned.
- If
-
attributes
Accessor for attributes (will create attributes list if needed) -
restrictions
Accessor for restrictions (will create restrictions list if needed). -
bindings
Accessor for bindings (will create binding map if needed). -
decode
Decodes a srs, supplying a useful error message if there is a problem. -
retype
Create a SimpleFeatureType containing just the attribute descriptors indicated.- Parameters:
original
- SimpleFeatureTypeattributes
- name of attributes to include in result- Returns:
- SimpleFeatureType containing just the types indicated by name
-
retype
Create a SimpleFeatureType containing just the attribute descriptors indicated.- Parameters:
original
- SimpleFeatureTypeattributes
- name of attributes to include in result- Returns:
- SimpleFeatureType containing just the types indicated by name
-
retype
Create a SimpleFeatureType with the same content; just updating the geometry attribute to match the provided coordinate reference system.- Parameters:
original
- SimpleFeatureTypecrs
- CoordinateReferenceSystem of result- Returns:
- SimpleFeatureType updated with the provided CoordinateReferenceSystem
-
retype
Create a SimpleFeatureType with the parameters and coordinate reference system of the query.- Parameters:
original
- SimpleFeatureTypequery
- Query defining attributes and coordinate reference system- Returns:
- SimpleFeatureType updated with the provided CoordinateReferenceSystem
-
copy
Copies a feature type.This method does a deep copy in that all individual attributes are copied as well.
-