public class FeatureTransformer extends TransformerBase
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.
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");
Modifier and Type | Class and Description |
---|---|
static class |
FeatureTransformer.FeatureTranslator
Outputs gml without any fancy indents or newlines.
|
static class |
FeatureTransformer.FeatureTypeNamespaces |
TransformerBase.SchemaLocationSupport, TransformerBase.Task, TransformerBase.TranslatorSupport, TransformerBase.XMLReaderSupport
XMLNS_NAMESPACE
Constructor and Description |
---|
FeatureTransformer() |
Modifier and Type | Method and Description |
---|---|
void |
addSchemaLocation(String nsURI,
String uri) |
Translator |
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.
|
String |
getCollectionNamespace() |
String |
getCollectionPrefix() |
NamespaceSupport |
getFeatureNamespaces() |
FeatureTransformer.FeatureTypeNamespaces |
getFeatureTypeNamespaces() |
protected void |
loadGmlAttributes(Set 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 |
setLockId(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 |
setPadWithZeros(boolean padWithZeros) |
void |
setSrsName(String srsName)
Used to set the srsName attribute of the Geometries to be turned to xml.
|
createTransformer, createTransformTask, createXMLReader, getEncoding, getIndentation, isNamespaceDeclartionEnabled, isOmitXMLDeclaration, setEncoding, setIndentation, setNamespaceDeclarationEnabled, setOmitXMLDeclaration, transform, transform, transform, transform
public void setCollectionNamespace(String nsURI)
public String getCollectionNamespace()
public void setCollectionPrefix(String prefix)
public String getCollectionPrefix()
public void setNumDecimals(int numDecimals)
numDecimals
- the number of significant digits past the decimal to include in the
response.public void setPadWithZeros(boolean padWithZeros)
public void setForceDecimalEncoding(boolean forceDecimalEncoding)
public NamespaceSupport getFeatureNamespaces()
public FeatureTransformer.FeatureTypeNamespaces getFeatureTypeNamespaces()
public void setSrsName(String srsName)
srsName
- Spatial Reference System NameCRS.toSRS(CoordinateReferenceSystem, boolean)
public void setLockId(String lockId)
lockId
- The lockId of the lock on the WFS.public void setGmlPrefixing(boolean prefixGml)
prefixGml
- true if prefixing gml should be enabled. Default is disabled, no
gml prefixing.protected void loadGmlAttributes(Set gmlAtts)
gmlAtts
- Set of strings corresponding to element names on a type.public void setFeatureBounding(boolean featureBounding)
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 falsepublic void setCollectionBounding(boolean collectionBounding)
Defaults to true (for backwards compatibility), disable explicitly if you don't want feature collection bounds to be generated.
collectionBounding
- public Translator createTranslator(ContentHandler handler)
TransformerBase
createTranslator
in class TransformerBase
protected FeatureTransformer.FeatureTranslator createTranslator(ContentHandler handler, String prefix, String ns, FeatureTransformer.FeatureTypeNamespaces featureTypeNamespaces, TransformerBase.SchemaLocationSupport schemaLocationSupport)
Copyright © 1996–2019 Geotools. All rights reserved.