public class GML extends Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
GML.Version
Version of encoder to use
|
Constructor and Description |
---|
GML(GML.Version version)
Construct a GML utility class to work with the indicated version of GML.
|
Modifier and Type | Method and 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,
SimpleFeatureCollection collection) |
void |
encode(OutputStream out,
SimpleFeatureType simpleFeatureType)
Encode the provided SimpleFeatureType into an XSD file, using a target namespace
When encoding the simpleFeatureType:
target prefix/namespace can be provided by prefix and namespace parameters.
|
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 encoding
|
void |
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 XSDSchema |
xsd(SimpleFeatureType simpleFeatureType) |
protected XSDComplexTypeDefinition |
xsd(XSDSchema xsd,
ComplexType type,
XSDComplexTypeDefinition BASE_TYPE)
Build the XSD definition for the provided type.
|
public GML(GML.Version version)
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).
version
- Version of GML to usepublic void setLegacy(boolean legacy)
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.
legacy
- public void setNamespace(String prefix, String namespace)
prefix
- namespace
- public void setEncoding(Charset encoding)
encoding
- public void setBaseURL(URL baseURL)
public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
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.
crs
- protected void init()
version
- public void encode(OutputStream out, SimpleFeatureCollection collection) throws IOException
IOException
public void encode(OutputStream out, SimpleFeatureType simpleFeatureType) throws IOException
When encoding the simpleFeatureType:
simpleFeatureType
- To be encoded as an XSD documentprefix
- Prefix to use for for target namespacenamespace
- Target namespaceIOException
public SimpleFeatureType decodeSimpleFeatureType(URL schemaLocation, Name typeName) throws IOException
The XMLSchema does not include CoordinateReferenceSystem we need to ask you to supply this information.
schemaLocation
- typeName
- IOException
public SimpleFeatureCollection decodeFeatureCollection(InputStream in) throws IOException, SAXException, ParserConfigurationException
in
- IOException
SAXException
ParserConfigurationException
public SimpleFeatureCollection decodeFeatureCollection(InputStream in, boolean computeFullFeatureType) throws IOException, SAXException, ParserConfigurationException
in
- 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 attributesIOException
SAXException
ParserConfigurationException
public SimpleFeatureIterator decodeFeatureIterator(InputStream in) throws IOException, ParserConfigurationException, SAXException
The schema used by the XML is consulted to determine what element extends AbstractFeature.
in
- SAXException
ParserConfigurationException
IOException
public SimpleFeatureIterator decodeFeatureIterator(InputStream in, QName elementName) throws IOException, ParserConfigurationException, SAXException
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.
in
- InputStream used as a source of SimpleFeature contentxpath
- Optional xpath used to indicate simple feature element; the schema will be
checked for an entry that extends AbstratFeatureTypeSAXException
ParserConfigurationException
IOException
protected SimpleFeatureIterator iterator(StreamingParser parser)
This iterator is actually forgiving; and willing to "morph" content into a SimpleFeature if needed.
parser
- protected SimpleFeatureType simpleType(Object obj)
protected SimpleFeature simpleFeature(Object obj, SimpleFeatureType schema)
obj
- schema
- protected XSDSchema xsd(SimpleFeatureType simpleFeatureType) throws IOException
IOException
protected XSDComplexTypeDefinition xsd(XSDSchema xsd, ComplexType type, XSDComplexTypeDefinition BASE_TYPE)
The generated definition is recorded in the XSDSchema prior to being returned.
xsd
- The XSDSchema being worked ontype
- ComplexType to capture as an encoding, usually a SimpleFeatureTypeL_TYPE
- definition to use as the base type, or nullCopyright © 1996–2019 Geotools. All rights reserved.