Class GML
- Object
-
- GML
-
public class GML extends Object
UtilityClass for encoding GML content.This utility class uses a range of GeoTools technologies as required; if you would like finer grain control over the encoding process please review the source code of this class and take your own measures.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GML.Version
Version of encoder to use
-
Constructor Summary
Constructors Constructor Description GML(GML.Version version)
Construct a GML utility class to work with the indicated version of GML.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SimpleFeatureCollection
decodeFeatureCollection(InputStream in)
Decodes a feature collection from the stream provided.SimpleFeatureCollection
decodeFeatureCollection(InputStream in, boolean computeFullFeatureType)
Decodes a feature collection from the stream provided.SimpleFeatureIterator
decodeFeatureIterator(InputStream in)
Allow the parsing of features as a stream; the returned iterator can be used to step through the inputstream of content one feature at a time without loading everything into memory.SimpleFeatureIterator
decodeFeatureIterator(InputStream in, QName elementName)
Allow the parsing of features as a stream; the returned iterator can be used to step through the inputstream of content one feature at a time without loading everything into memory.SimpleFeatureType
decodeSimpleFeatureType(URL schemaLocation, Name typeName)
Decode a typeName from the provided schemaLocation.void
encode(OutputStream out, SimpleFeatureType simpleFeatureType)
Encode the provided SimpleFeatureType into an XSD file, using a target namespacevoid
encode(OutputStream out, SimpleFeatureCollection collection)
protected void
init()
Set up out of the box configuration for GML encoding.protected SimpleFeatureIterator
iterator(StreamingParser parser)
Used to wrap up a StreamingParser as a Iterator. void
setBaseURL(URL baseURL)
Base URL to use when encodingvoid
setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
Coordinate reference system to use when decoding.void
setEncoding(Charset encoding)
Set the encoding to use.void
setLegacy(boolean legacy)
Engage legacy support for GML2.void
setNamespace(String prefix, String namespace)
Set the target namespace for the encoding.protected SimpleFeature
simpleFeature(Object obj, SimpleFeatureType schema)
Morph provided obj to a SimpleFeature if possible.protected SimpleFeatureType
simpleType(Object obj)
protected XSDComplexTypeDefinition
xsd(XSDSchema xsd, ComplexType type, XSDComplexTypeDefinition BASE_TYPE)
Build the XSD definition for the provided type.protected XSDSchema
xsd(SimpleFeatureType simpleFeatureType)
-
-
-
Constructor Detail
-
GML
public GML(GML.Version version)
Construct a GML utility class to work with the indicated version of GML.Note that when working with GML2 you need to supply additional information prior to use (in order to indicate where for XSD file is located).
- Parameters:
version
- Version of GML to use
-
-
Method Detail
-
setLegacy
public void setLegacy(boolean legacy)
Engage legacy support for GML2.The GML2 support for FeatureTransformer is much faster then that provided by the GTXML parser/encoder. This speed is at the expense of getting the up front configuration exactly correct (something you can only tell when parsing the produced result!). Setting this value to false will use the same GMLConfiguration employed when parsing and has less risk of producing invalid content.
-
setNamespace
public void setNamespace(String prefix, String namespace)
Set the target namespace for the encoding.
-
setEncoding
public void setEncoding(Charset encoding)
Set the encoding to use.
-
setBaseURL
public void setBaseURL(URL baseURL)
Base URL to use when encoding
-
setCoordinateReferenceSystem
public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
Coordinate reference system to use when decoding.In a few cases (such as decoding a SimpleFeatureType) the file format does not include the required CooridinateReferenceSystem and you are asked to supply it.
-
init
protected void init()
Set up out of the box configuration for GML encoding.- GML2
- GML3
- gml3.2 - not yet available
- wfs1.0 - not yet available
- wfs1.1 - not yet available
-
encode
public void encode(OutputStream out, SimpleFeatureCollection collection) throws IOException
- Throws:
IOException
-
encode
public void encode(OutputStream out, SimpleFeatureType simpleFeatureType) throws IOException
Encode the provided SimpleFeatureType into an XSD file, using a target namespaceWhen encoding the simpleFeatureType:
- target prefix/namespace can be provided by prefix and namespace parameters. This is the default for the entire XSD document.
- simpleFeatureType.geName().getNamespaceURI() is used for the simpleFeatureType itself, providing simpleFeatureType.getUserData().get("prefix") is defined
- Parameters:
simpleFeatureType
- To be encoded as an XSD document- Throws:
IOException
-
decodeSimpleFeatureType
public SimpleFeatureType decodeSimpleFeatureType(URL schemaLocation, Name typeName) throws IOException
Decode a typeName from the provided schemaLocation.The XMLSchema does not include CoordinateReferenceSystem we need to ask you to supply this information.
- Returns:
- SimpleFeatureType
- Throws:
IOException
-
decodeFeatureCollection
public SimpleFeatureCollection decodeFeatureCollection(InputStream in) throws IOException, SAXException, ParserConfigurationException
Decodes a feature collection from the stream provided. It assumes the features are uniform and that all attributes are available in the first feature
-
decodeFeatureCollection
public SimpleFeatureCollection decodeFeatureCollection(InputStream in, boolean computeFullFeatureType) throws IOException, SAXException, ParserConfigurationException
Decodes a feature collection from the stream provided.- Parameters:
computeFullFeatureType
- When true, all features are parsed and then a global feature type is determined that has attributes covering all feature needs, when false, the first feature attributes- Throws:
IOException
SAXException
ParserConfigurationException
-
decodeFeatureIterator
public SimpleFeatureIterator decodeFeatureIterator(InputStream in) throws IOException, ParserConfigurationException, SAXException
Allow the parsing of features as a stream; the returned iterator can be used to step through the inputstream of content one feature at a time without loading everything into memory.The schema used by the XML is consulted to determine what element extends AbstractFeature.
- Returns:
- Iterator that can be used to parse features one at a time
- Throws:
IOException
ParserConfigurationException
SAXException
-
decodeFeatureIterator
public SimpleFeatureIterator decodeFeatureIterator(InputStream in, QName elementName) throws IOException, ParserConfigurationException, SAXException
Allow the parsing of features as a stream; the returned iterator can be used to step through the inputstream of content one feature at a time without loading everything into memory.The use of an elementName is optional; and can be used as a workaround in cases where the schema is not available or correctly defined. The returned elements are wrapped up as a Feature if needed. This mehtod can be used to retrive only the Geometry elements from a GML docuemnt.
- Parameters:
in
- InputStream used as a source of SimpleFeature contentelementName
- The simple feature element; the schema will be checked for an entry that extends AbstratFeatureType- Throws:
IOException
ParserConfigurationException
SAXException
-
iterator
protected SimpleFeatureIterator iterator(StreamingParser parser)
Used to wrap up a StreamingParser as a Iterator. This iterator is actually forgiving; and willing to "morph" content into a SimpleFeature if needed.
- SimpleFeature - is returned as is
-
simpleType
protected SimpleFeatureType simpleType(Object obj)
-
simpleFeature
protected SimpleFeature simpleFeature(Object obj, SimpleFeatureType schema)
Morph provided obj to a SimpleFeature if possible.- Returns:
- SimpleFeature, or null if not possible
-
xsd
protected XSDSchema xsd(SimpleFeatureType simpleFeatureType) throws IOException
- Throws:
IOException
-
xsd
protected XSDComplexTypeDefinition xsd(XSDSchema xsd, ComplexType type, XSDComplexTypeDefinition BASE_TYPE)
Build the XSD definition for the provided type.The generated definition is recorded in the XSDSchema prior to being returned.
- Parameters:
xsd
- The XSDSchema being worked ontype
- ComplexType to capture as an encoding, usually a SimpleFeatureTypeBASE_TYPE
- definition to use as the base type, or null- Returns:
- XSDComplexTypeDefinition generated for the provided type
-
-