org.geotools
Class GML

Object
  extended by 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
static class GML.Version
          Version of encoder to use
 
Constructor Summary
GML(GML.Version version)
          Construct a GML utility class to work with the indicated version of GML.
 
Method Summary
 SimpleFeatureCollection decodeFeatureCollection(InputStream in)
           
 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.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.

Parameters:
legacy -

setNamespace

public void setNamespace(String prefix,
                         String namespace)
Set the target namespace for the encoding.

Parameters:
prefix -
namespace -

setEncoding

public void setEncoding(Charset encoding)
Set the encoding to use.

Parameters:
encoding -

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.

Parameters:
crs -

init

protected void init()
Set up out of the box configuration for GML encoding. The following are not avialable yet:

Parameters:
version -

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 namespace

When encoding the simpleFeatureType:

Parameters:
simpleFeatureType - To be encoded as an XSD document
prefix - Prefix to use for for target namespace
namespace - Target namespace
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.

Parameters:
schemaLocation -
typeName -
Returns:
SimpleFeatureType
Throws:
IOException

decodeFeatureCollection

public SimpleFeatureCollection decodeFeatureCollection(InputStream in)
                                                throws IOException,
                                                       SAXException,
                                                       ParserConfigurationException
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.

Parameters:
in -
Returns:
Iterator that can be used to parse features one at a time
Throws:
SAXException
ParserConfigurationException
IOException

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 content
xpath - Optional xpath used to indicate simple feature element; the schema will be checked for an entry that extends AbstratFeatureType
Returns:
Throws:
SAXException
ParserConfigurationException
IOException

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
  • Parameters:
    parser -
    Returns:

simpleType

protected SimpleFeatureType simpleType(Object obj)

simpleFeature

protected SimpleFeature simpleFeature(Object obj,
                                      SimpleFeatureType schema)
Morph provided obj to a SimpleFeature if possible.

Parameters:
obj -
schema -
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 on
type - ComplexType to capture as an encoding, usually a SimpleFeatureType
L_TYPE - definition to use as the base type, or null
Returns:
XSDComplexTypeDefinition generated for the provided type


Copyright © 1996-2014 Geotools. All Rights Reserved.