Class FeatureTransformer

  extended byorg.geotools.xml.transform.TransformerBase
      extended byorg.geotools.gml.producer.FeatureTransformer

public class FeatureTransformer
extends TransformerBase

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:

    FeatureCollection collection; // can also use FeatureReader!!
   OutputStream out;
    FeatureTransformer ft = new FeatureTransformer();
    // set the indentation to 4 spaces
    // this will allow Features with the FeatureType which has the namespace
   // "" to be prefixed with xxx...
    // transform
The above example assumes a homogenous collection of Features whose FeatureType has the namespace "" 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();
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();

The collectionNamespace and prefix property refers to the prefix and namespace given to the document root and defualts to wfs,http://www.opengis.wfs.

$Id: 17701 2006-01-23 00:00:51Z desruisseaux $
Ian Schneider, Chris Holmes, TOPP
To Do:
Add support for schemaLocation

Nested Class Summary
static class FeatureTransformer.FeatureTranslator
          Outputs gml without any fancy indents or newlines.
static class FeatureTransformer.FeatureTypeNamespaces
Nested classes inherited from class org.geotools.xml.transform.TransformerBase
TransformerBase.SchemaLocationSupport, TransformerBase.Task, TransformerBase.TranslatorSupport, TransformerBase.XMLReaderSupport
Constructor Summary
Method Summary
 void addSchemaLocation(java.lang.String nsURI, java.lang.String uri)
 Translator createTranslator(org.xml.sax.ContentHandler handler)
          Create a Translator to issue SAXEvents to a ContentHandler.
 java.lang.String getCollectionNamespace()
 java.lang.String getCollectionPrefix()
 org.xml.sax.helpers.NamespaceSupport getFeatureNamespaces()
 FeatureTransformer.FeatureTypeNamespaces getFeatureTypeNamespaces()
 void setCollectionNamespace(java.lang.String nsURI)
 void setCollectionPrefix(java.lang.String prefix)
 void setFeatureBounding(boolean featureBounding)
          Sets whether a gml:boundedBy element should automatically be generated and included.
 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 setLockId(java.lang.String lockId)
          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 setSrsName(java.lang.String srsName)
          Used to set the srsName attribute of the Geometries to be turned to xml.
Methods inherited from class org.geotools.xml.transform.TransformerBase
createTransformer, createTransformTask, createXMLReader, getEncoding, getIndentation, isNamespaceDeclartionEnabled, isOmitXMLDeclaration, setEncoding, setIndentation, setNamespaceDeclarationEnabled, setOmitXMLDeclaration, transform, transform, transform, transform
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public FeatureTransformer()
Method Detail


public void setCollectionNamespace(java.lang.String nsURI)


public java.lang.String getCollectionNamespace()


public void setCollectionPrefix(java.lang.String prefix)


public java.lang.String getCollectionPrefix()


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.

numDecimals - the number of significant digits past the decimal to include in the response.


public org.xml.sax.helpers.NamespaceSupport getFeatureNamespaces()


public FeatureTransformer.FeatureTypeNamespaces getFeatureTypeNamespaces()


public void addSchemaLocation(java.lang.String nsURI,
                              java.lang.String uri)


public void setSrsName(java.lang.String srsName)
Used to set the srsName attribute of the Geometries to be turned to xml. For now we can only have all with the same srsName.

srsName - DOCUMENT ME!
REVISIT: once we have better srs support in our feature model this should be rethought, as it's a rather blunt approach.


public void setLockId(java.lang.String lockId)
Used to set a lockId attribute after a getFeatureWithLock.

lockId - The lockId of the lock on the WFS.
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


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.

prefixGml - true if prefixing gml should be enabled. Default is disabled, no gml prefixing.
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.


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

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


public Translator createTranslator(org.xml.sax.ContentHandler handler)
Description copied from class: TransformerBase
Create a Translator to issue SAXEvents to a ContentHandler.

Specified by:
createTranslator in class TransformerBase

Copyright © GeoTools. All Rights Reserved.