Package org.geotools.gml.producer
Class FeatureTransformer
Object
TransformerBase
FeatureTransformer
FeatureTransformer provides a mechanism for converting Feature objects into (hopefully) valid gml. This is a work in
progress, so please be patient. A simple example of how to use this class follows:
1) Map a specific FeatureType by identity to prefix and nsURI
The collectionNamespace and prefix property refers to the prefix and namespace given to the document root and defualts to wfs,http://www.opengis.wfs.
SimpleFeatureCollection collection; // can also use FeatureReader!! OutputStream out; FeatureTransformer ft = new FeatureTransformer(); // set the indentation to 4 spaces ft.setIndentation(4); // this will allow Features with the FeatureType which has the namespace // "http://somewhere.org" to be prefixed with xxx... ft.getFeatureNamespaces().declarePrefix("xxx","http://somewhere.org"); // transform ft.transform(collection,out);The above example assumes a homogenous collection of Features whose FeatureType has the namespace "http://somewhere.org" but note that not all DataSources currently provide FeatureTypes with a namespace... There are two other mechanisms for prefixing your Features.
1) Map a specific FeatureType by identity to prefix and nsURI
FeatureType fc; FeatureTransformer ft = new FeatureTransformer(); ft.getFeatureTypeNamespaces().declareNamespace(fc,"xxx","http://somewhere.org");2) Provide a default namespace for any Features whose FeatureType either has an empty namespace, OR, has not been mapped using the previous method. This is basically a catch-all mechanism.
FeatureTransformer ft = new FeatureTransformer(); ft.getFeatureTypeNamespaces().declareDefaultNamespace("xxx","http://somewhere.org");
The collectionNamespace and prefix property refers to the prefix and namespace given to the document root and defualts to wfs,http://www.opengis.wfs.
- Author:
- Ian Schneider, Chris Holmes, TOPP
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Outputs gml without any fancy indents or newlines.static class
Nested classes/interfaces inherited from class TransformerBase
TransformerBase.SchemaLocationSupport, TransformerBase.Task, TransformerBase.TranslatorSupport, TransformerBase.XMLReaderSupport
-
Field Summary
Fields inherited from class TransformerBase
XMLNS_NAMESPACE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addSchemaLocation
(String nsURI, String uri) createTranslator
(ContentHandler handler) Create a Translator to issue SAXEvents to a ContentHandler.protected FeatureTransformer.FeatureTranslator
createTranslator
(ContentHandler handler, String prefix, String ns, FeatureTransformer.FeatureTypeNamespaces featureTypeNamespaces, TransformerBase.SchemaLocationSupport schemaLocationSupport) Template method for creating the translator.protected void
loadGmlAttributes
(Set<String> gmlAtts) Template method for determining which attributes to prefix with gml.void
setCollectionBounding
(boolean collectionBounding) If true, enables the generation of the full collection bounds.void
setCollectionNamespace
(String nsURI) void
setCollectionPrefix
(String prefix) void
setFeatureBounding
(boolean featureBounding) Sets whether a gml:boundedBy element should automatically be generated and included.void
setForceDecimalEncoding
(boolean forceDecimalEncoding) void
setGmlPrefixing
(boolean prefixGml) If Gml Prefixing is enabled then attributes with names that could be prefixed with gml, such as description, pointProperty, and name, will be.void
Used to set a lockId attribute after a getFeatureWithLock.void
setNumDecimals
(int numDecimals) Sets the number of decimals to be used in the geometry coordinates of the response.void
setPadWithZeros
(boolean padWithZeros) void
setSrsName
(String srsName) Used to set the srsName attribute of the Geometries to be turned to xml.Methods inherited from class TransformerBase
createTransformer, createTransformTask, createXMLReader, getEncoding, getIndentation, isNamespaceDeclartionEnabled, isOmitXMLDeclaration, setEncoding, setIndentation, setNamespaceDeclarationEnabled, setOmitXMLDeclaration, transform, transform, transform, transform
-
Constructor Details
-
FeatureTransformer
public FeatureTransformer()
-
-
Method Details
-
setCollectionNamespace
-
getCollectionNamespace
-
setCollectionPrefix
-
getCollectionPrefix
-
setNumDecimals
public void setNumDecimals(int numDecimals) Sets the number of decimals to be used in the geometry coordinates of the response. This allows for more efficient results, since often the storage format itself won't specify as many decimal places as the response might want. The default is 4, but should generally be set by the user of this class.- Parameters:
numDecimals
- the number of significant digits past the decimal to include in the response.
-
setPadWithZeros
public void setPadWithZeros(boolean padWithZeros) -
setForceDecimalEncoding
public void setForceDecimalEncoding(boolean forceDecimalEncoding) -
getFeatureNamespaces
-
getFeatureTypeNamespaces
-
addSchemaLocation
-
setSrsName
Used to set the srsName attribute of the Geometries to be turned to xml. The srsName is applied to all the geometries and is not done on a case by case basis.- Parameters:
srsName
- Spatial Reference System Name- See Also:
- TODO:
- REVISIT: once we have better srs support in our feature model this should be rethought, as it's a rather blunt approach.
-
setLockId
Used to set a lockId attribute after a getFeatureWithLock.- Parameters:
lockId
- The lockId of the lock on the WFS.- TODO:
- REVISIT: Ian, this is probably the most wfs specific addition. If you'd like I can subclass and add it there. It has to be added as an attribute to FeatureCollection, to report a GetFeatureWithLock
-
setGmlPrefixing
public void setGmlPrefixing(boolean prefixGml) If Gml Prefixing is enabled then attributes with names that could be prefixed with gml, such as description, pointProperty, and name, will be. So if an attribute called name is encountered, instead of prepending the default prefix (say gt2:name), it will turn out as gml:name. Right now this is fairly hacky, as the gml:name, gml:description, ect., should be in the first attributes by default. The actualy geometry encodings will always be prefixed with the proper gml, like gml:coordinates. This only applies to attributes, that could also be part of the features normal schema (for example a pointProperty could be declared in the gt2 namespace, instead of a gml:pointProperty it would be a gt2:pointProperty.- Parameters:
prefixGml
- true if prefixing gml should be enabled. Default is disabled, no gml prefixing.- TODO:
- REVISIT: only prefix name, description, and boundedBy if they occur in their proper places. Right now names always get gml prefixed if the gmlPrefixing is on, which is less than ideal., REVISIT: The other approach is to allow for generic mapping, users would set which attributes they wanted to have different prefixes.
-
loadGmlAttributes
Template method for determining which attributes to prefix with gml.- Parameters:
gmlAtts
- Set of strings corresponding to element names on a type.
-
setFeatureBounding
public void setFeatureBounding(boolean featureBounding) Sets whether a gml:boundedBy element should automatically be generated and included. The element will not be updateable, and is simply derived from the geometries present in the feature.Note that the setGmlPrefixing() interacts with this occasionally, since it will hack in a gml prefix to a boundedBy attribute included in the featureType. If gml prefixing is on, and featureBounding is on, then the bounds from the attribute will be used. If gml prefixing is off, then that boundedBy attribute will presumably be in its own namespace, and so the automatic gml boundedBy will not conflict, so both will be printed, with the automatic one deriving its bounds from the boundedBy attribute and any other geometries in the feature
- Parameters:
featureBounding
- true if the bounds of the feature should be automatically calculated and included as a gml:boundedBy in the gml output. Note this puts a good bit of bandwidth overhead on the output. Default is false
-
setCollectionBounding
public void setCollectionBounding(boolean collectionBounding) If true, enables the generation of the full collection bounds. Depending on the collection being generated in output, this operation can be extremely expensive.Defaults to true (for backwards compatibility), disable explicitly if you don't want feature collection bounds to be generated.
-
createTranslator
Description copied from class:TransformerBase
Create a Translator to issue SAXEvents to a ContentHandler.- Specified by:
createTranslator
in classTransformerBase
-
createTranslator
protected FeatureTransformer.FeatureTranslator createTranslator(ContentHandler handler, String prefix, String ns, FeatureTransformer.FeatureTypeNamespaces featureTypeNamespaces, TransformerBase.SchemaLocationSupport schemaLocationSupport) Template method for creating the translator.
-