@LcdService(service=ILcdModelDecoder.class, priority=20001) public class TLcdGMLModelDecoder extends ALcdXMLModelDecoder
File | Required | Entry point | Description |
---|---|---|---|
*.gml, *.gml2, *.gml31, *.gml32, *.xml | x | x |
GML data file |
*.xsd | x | Application schema (XML Schema) |
ILcdInputStreamFactory
of this decoder.AbstractFeatureMemberType
.
Elements of the deprecated AbstractFeatureCollectionType
types also supported.ILcd2DBoundsIndexedModel
.ILcdModelTreeNode
structure.
For example, the following document:
<my:featureCollectionA>
<my:featureCollectionB>
<my:featureA>
...
</my:featureA>
</my:featureCollectionB>
<my:featureCollectionC>
<my:featureB>
...
</my:featureB>
</my:featureCollectionC>
<my:featureC>
...
</my:featureC>
</my:featureCollectionA>
will be decoded as the followed model/element structure:
ILcdModelTreeNode (myFeatureCollectionA) +- ILcdModelTreeNode (myFeatureCollectionB) | +- ILcdShape (myFeatureA) +- ILcdModelTreeNode (myFeatureCollectionC) | +- ILcdShape (myFeatureB) +- ILcdShape (myFeatureC)
TLcdGMLModelDescriptor
.TLcdOGCModelReferenceParser
.
srsName
attribute specified
within the GML files. The first coordinate reference system (CRS) that is encountered is
used as the model reference. Geographic data defined in other CRS'es are transformed during
decoding to this model reference CRS.ILcdDataObject
.
Refer to the javadoc of the version specific GML decoders for more information.
EntityResolver2
can be configured
on this model decoder, to control
how to resolve external entities (such as XSD schemas). By default, an entity resolver is configured
which resolves references to all OGC schemas supported by LuciadLightspeed.
ILcdModelDecoder decoder = new TLcdGMLModelDecoder();
ILcdModel model = decoder.decode("world.gml32");
Constructor and Description |
---|
TLcdGMLModelDecoder()
Constructs a new
TLcdGMLModelDecoder . |
TLcdGMLModelDecoder(TLcdDataModel aDataModel)
Creates a new
TLcdGMLModelDecoder configured for the given data model. |
Modifier and Type | Method and Description |
---|---|
boolean |
canDecodeSource(String aSourceName)
Checks whether this model decoder can decode the specified data source.
|
ILcdModel |
decode(Source aSource)
Creates a new model from the given data source.
|
ILcdModel |
decode(String aSourceName)
Creates a new model from the given data source.
|
String |
getDefaultSrsName()
Get the default srsName for this instance.
|
String |
getDisplayName()
Returns a short, displayable name for the format that is decoded by this
ILcdModelDecoder . |
EntityResolver2 |
getEntityResolver()
Returns the
org.xml.sax.ext.EntityResolver2 that is used for creating input sources for
XSD schemas. |
ILcdInputStreamFactory |
getInputStreamFactory()
Returns the
ILcdInputStreamFactory that is used for creating input streams. |
ILcdModelReferenceParser |
getModelReferenceParser()
Returns the model reference parser that is used to create
ILcdModelReference
instances when decoding an srsName. |
XMLInputFactory |
getXMLInputFactory()
Returns the
javax.xml.stream.XMLInputFactory that is used by this decoder for creating
javax.xml.stream.XMLStreamReader instances. |
boolean |
isLinearElementsUseGeodesicInterpolationForGeodeticSrs()
Returns
true if a geodesic interpolation needs to be used for linear GML elements in case of a geodetic
reference. |
boolean |
isUseApplicationSchemaCache()
Returns if application schemas are cached.
|
void |
setDefaultSrsName(String aDefaultSrsName)
Set the default srsName that will be used to determine the model reference if
neither the first feature, its possible envelope or the possible envelope of the feature collection has
a srsName attribute set.
|
void |
setEntityResolver(EntityResolver2 aEntityResolver)
Sets the
org.xml.sax.ext.EntityResolver2 to be used for creating input sources for
XSD schemas. |
void |
setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
Sets the
ILcdInputStreamFactory to be used for creating input streams. |
void |
setLinearElementsUseGeodesicInterpolationForGeodeticSrs(boolean aUseGeodesicInterpolationForGeodeticSrs)
Sets whether a geodesic interpolation needs to be used for linear GML elements in case of a geodetic reference.
|
void |
setModelReferenceParser(ILcdModelReferenceParser aModelReferenceParser)
Sets the parser that is used to create
ILcdModelReference instances
given an srsName. |
void |
setUseApplicationSchemaCache(boolean aUseCache)
Enables or disables application schema caching depending on the parameter value.
|
void |
setXMLInputFactory(XMLInputFactory aXMLInputFactory)
Sets the
javax.xml.stream.XMLInputFactory to be used by this decoder for creating
javax.xml.stream.XMLStreamReader instances. |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
canDecodeSource, decodeModelMetadata, decodeModelMetadata, decodeSource, discoverDataSources
public TLcdGMLModelDecoder()
TLcdGMLModelDecoder
.public TLcdGMLModelDecoder(TLcdDataModel aDataModel)
TLcdGMLModelDecoder
configured for the given data model.aDataModel
- the data model for which the decoder is to be configuredIllegalArgumentException
- if the data model does not depend on either the GML 2, GML 31 or GML32 data modelpublic boolean canDecodeSource(String aSourceName)
ILcdModelDecoder
true
for a source name while decode
throws an exception for that same source name.
For performance reasons, we strongly recommend that this will only be a simple test. For example: check the file extension of a file, but not that the file exists or contains expected content.
aSourceName
- the data source to be verified; typically a file name or a URL.true
if this decoder can likely decode the data specified by the source name, false
otherwise.ILcdModelDecoder.decode(String)
,
ILcdModelDecoder.decodeModelMetadata(String)
public ILcdModel decode(String aSourceName) throws IOException
ILcdModelDecoder
aSourceName
- the data source to be decoded; typically a file name or a URL.null
is allowed, implementors are advised to throw an error instead.IOException
- for any exceptions caused by IO problems or invalid data. Since decoding invalid data almost
always results in RunTimeExceptions (NullPointerException, IndexOutOfBoundsException,
IllegalArgumentException, ...) on unexpected places, implementations are advised to catch
RuntimeExceptions in their decode() method, and wrap them into an IOException, as illustrated
in the code snippet below.
public ILcdModel decode( String aSourceName ) throws IOException {
try (InputStream input = fInputStreamFactory.createInputStream(aSourceName)) {
// Perform decoding ...
} catch (RuntimeException e) {
throw new IOException(e);
}
}
InterruptedIOException
- When the thread on which this method is called is interrupted: it is recommended to stop the decoding
and throw an InterruptedIOException
.
This same exception can also be used if the decoder shows UI to the user, and the user cancels the decoding
through the UI.ILcdModelDecoder.canDecodeSource(String)
public String getDisplayName()
ILcdModelDecoder
ILcdModelDecoder
.ILcdModelDecoder
.public EntityResolver2 getEntityResolver()
ALcdXMLModelDecoder
org.xml.sax.ext.EntityResolver2
that is used for creating input sources for
XSD schemas. This entity resolver will only be used to resolve extension schemas that are
not already configured on this decoder.getEntityResolver
in class ALcdXMLModelDecoder
public ILcdInputStreamFactory getInputStreamFactory()
ALcdXMLModelDecoder
ILcdInputStreamFactory
that is used for creating input streams.getInputStreamFactory
in interface ILcdInputStreamFactoryCapable
getInputStreamFactory
in class ALcdXMLModelDecoder
ILcdInputStreamFactory
that is used for creating input streams.ALcdXMLModelDecoder.setInputStreamFactory(com.luciad.io.ILcdInputStreamFactory)
public XMLInputFactory getXMLInputFactory()
ALcdXMLModelDecoder
javax.xml.stream.XMLInputFactory
that is used by this decoder for creating
javax.xml.stream.XMLStreamReader
instances.getXMLInputFactory
in class ALcdXMLModelDecoder
javax.xml.stream.XMLInputFactory
that is used by this decoder for creating
javax.xml.stream.XMLStreamReader
instances.public boolean isUseApplicationSchemaCache()
ALcdXMLModelDecoder
Returns if application schemas are cached. When application schemas are cached, the decoder caches all applications schemas it encounters. When a certain schema is referenced during decoding, only if the schema is not found in the cache, it will be resolved. The default is not to cache.
Note that in case multiple application schemas use the same namespace URI, it is not possible to turn on application schema caching because the decoder will not be able to discern between the different schemas.
isUseApplicationSchemaCache
in class ALcdXMLModelDecoder
public void setEntityResolver(EntityResolver2 aEntityResolver)
ALcdXMLModelDecoder
Sets the org.xml.sax.ext.EntityResolver2
to be used for creating input sources for
XSD schemas.
When the
entity resolver is unable to find a schema (i.e. the resolveEntity
method
returns null
), the ALcdXMLModelDecoder.getInputStreamFactory()
is used to
create an appropriate input stream for the given system id of the schema.
setEntityResolver
in class ALcdXMLModelDecoder
aEntityResolver
- the entity resolver to be used for creating input sources for XSD schemas.public void setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
ALcdXMLModelDecoder
ILcdInputStreamFactory
to be used for creating input streams.
If the configured entity resolver
implements ILcdInputStreamFactoryCapable
,
it is also configured with this factory.setInputStreamFactory
in interface ILcdInputStreamFactoryCapable
setInputStreamFactory
in class ALcdXMLModelDecoder
aInputStreamFactory
- the input stream factory to be used by this model decoder.ALcdXMLModelDecoder.getInputStreamFactory()
public void setUseApplicationSchemaCache(boolean aUseCache)
ALcdXMLModelDecoder
setUseApplicationSchemaCache
in class ALcdXMLModelDecoder
aUseCache
- if true, application schema caching is turned on. If false,
caching is turned off.public void setXMLInputFactory(XMLInputFactory aXMLInputFactory)
javax.xml.stream.XMLInputFactory
to be used by this decoder for creating
javax.xml.stream.XMLStreamReader
instances.
If the configured entity resolver
implements ILcdInputStreamFactoryCapable
,
it is also configured with this factory.setXMLInputFactory
in class ALcdXMLModelDecoder
aXMLInputFactory
- the javax.xml.stream.XMLInputFactory
to be used by this decoderpublic ILcdModelReferenceParser getModelReferenceParser()
ILcdModelReference
instances when decoding an srsName.public void setModelReferenceParser(ILcdModelReferenceParser aModelReferenceParser)
ILcdModelReference
instances
given an srsName.aModelReferenceParser
- the model reference parser for this decoderpublic void setDefaultSrsName(String aDefaultSrsName)
By default, the model decoder uses CRS84.
aDefaultSrsName
- the default srsNameIllegalArgumentException
- if the srsName can not be parsed.public String getDefaultSrsName()
setDefaultSrsName(String)
public ILcdModel decode(Source aSource) throws IOException
Creates a new model from the given data source.
This implementation only supports StreamSource
sources. In case other
types of sources are required, the version-specific GML decoders should be used
directly.
decode
in class ALcdXMLModelDecoder
aSource
- the source to read the model fromUnsupportedOperationException
- in case the decoder is not able to decode
from the sourceIOException
decode(String)
public void setLinearElementsUseGeodesicInterpolationForGeodeticSrs(boolean aUseGeodesicInterpolationForGeodeticSrs)
LinearRing
, LineString
and
LineStringSegment
.
Although these GML elements conceptually represent geometries with a linear interpolation, they are often used to
represent geometries with lon/lat coordinates and a geodesic interpolation.. Setting this flag to true
enables this
use case by determining the interpolation based on the coordinate reference.
aUseGeodesicInterpolationForGeodeticSrs
- whether a geodesic interpolation needs to be used in case of a geodetic referenceisLinearElementsUseGeodesicInterpolationForGeodeticSrs()
public boolean isLinearElementsUseGeodesicInterpolationForGeodeticSrs()
true
if a geodesic interpolation needs to be used for linear GML elements in case of a geodetic
reference. By default, true
is returned.true
if a geodesic interpolation needs to be used for linear GML elements in case of a geodetic reference.setLinearElementsUseGeodesicInterpolationForGeodeticSrs(boolean)