Class TLcdKML22ModelDecoder
- All Implemented Interfaces:
ILcdInputStreamFactoryCapable,ILcdModelDecoder
ILcdModel objects.
Input files
| File | Required | Entry point | Description |
|---|---|---|---|
| *.kml | x | A KML file | |
| *.kmz | x | Zip archive containing a KML (.kml) file and possibly other resources |
Supported file transfer protocols
- This model decoder supports all transfer protocols that are supported by
the
inputStreamFactoryof this decoder.
Model structure
- This model decoder creates a
TLcdKML22Kmlmodel per KML file. - All models (
TLcdKML22Kmlinstances) returned by this model decoder implementILcdModelTreeNode,ILcd2DBoundsIndexedModelandILcdIntegerIndexedModel. - A
TLcdKML22Kmlhas a hierarchical structure, which is organized in accordance with the KML file. The following model implementations can be encountered in the KML model hierarchy:
For example, a sample KML file with the following file structure:KML container type LuciadLightspeed KML class Implemented LuciadLightspeed interfaces KML TLcdKML22KmlILcdModelTreeNode, ILcd2DBoundsIndexedModel, ILcdIntegerIndexedModelAbstract container TLcdKML22AbstractContainerILcdModelTreeNode, ILcd2DBoundsIndexedModel, ILcdIntegerIndexedModelDocument TLcdKML22DocumentILcdModelTreeNode, ILcd2DBoundsIndexedModel, ILcdIntegerIndexedModelFolder TLcdKML22FolderILcdModelTreeNode, ILcd2DBoundsIndexedModel, ILcdIntegerIndexedModelNetwork Link TLcdKML22NetworkLinkILcdModelTreeNode
will be decoded into the following model hierarchy:<kml> <document> <folder> <placemark>...</placemark> </folder> </document> </kml>TLcdKML22Kml (implements ILcdModelTreeNode) | +-- TLcdKML22Document (implements ILcdModelTreeNode) | + TLcdKML22Folder (implements ILcdModelTreeNode) -> has placemark element.
Model descriptor
- All models returned by this model decoder have a
TLcdKML22ModelDescriptor. - All models returned by this model decoder will have a model descriptor with a TLcdKML22ResourceProvider. This is for convenience. The TLcdKML22ResourceProvider itself is not used in the decoded model, but can be used when constructing TLcdKML22DynamicModel instances. Note that only the root model will have this resource provider in its model decoder.
- The type name of the model descriptor is the display name of this decoder.
Model reference
- All models returned by this model decoder have a
TLcdGeodeticReference, WGS84. - This model reference is imposed by the KML specification.
Model elements
- The following table gives an overview of all possible elements that can occur in a model,
together with the main LuciadLightspeed interfaces they implement:
KML type LuciadLightspeed KML class Implemented LuciadLightspeed interfaces Placemark TLcdKML22PlacemarkILcdShapeListGround overlay TLcdKML22GroundOverlayILcdBoundedScreen overlay TLcdKML22ScreenOverlayPhoto overlay TLcdKML22PhotoOverlayILcdBoundedDAE (3D) model TLcdKML223DModelILcdBounded
Useful settings
- KML models can contain dynamic contents. In order to enable dynamic contents,
a static KML model (
TLcdKML22Kmlinstance) needs to be wrapped in aTLcdKML22DynamicModel. This model will resolve and include dynamic contents on-the-fly. - In order to be rendered with the correct object order, a
TLcdKMl22DynamicModelcan be wrapped in aTLcdKML22RenderableModel. This model will flatten the model hierarchy of aTLcdKML22Kmland make sure all objects are processed (via eitherapplyOnInteractorelementsin the right order.
Sample code
Decoding and visualizing KML data on a Lightspeed view: //First create the model
ILcdModelDecoder decoder =
new TLcdCompositeModelDecoder(TLcdServiceLoader.getInstance(ILcdModelDecoder.class));
ILcdModel model = decoder.decode("Data/Kml/luciad.kml");
//Create a layer for the model using the layer builder
ILspLayer layer = TLspKML22LayerBuilder.newBuilder()
.model(model)
.build();
//Add the layer to the Lightspeed view (an ILspView)
view.addLayer(layer);
//First create the model
ILcdModelDecoder decoder =
new TLcdCompositeModelDecoder(TLcdServiceLoader.getInstance(ILcdModelDecoder.class));
ILcdModel model = decoder.decode("Data/Kml/luciad.kml");
//Create a layer for the model
ILcdGXYLayer layer = new TLcdKML22GXYLayerFactory().createGXYLayer(model);
//Wrap the layer with an async layer wrapper to ensure
//that the view remains responsive while data is being painted
layer = ILcdGXYAsynchronousLayerWrapper.create(layer);
//Add the async layer to the GXY view (an ILcdGXYView)
view.addGXYLayer(layer);
Performance tips
Thread safety
- The decoding of models is thread-safe.
Supported versions and specifications
- This model decoder fully supports OGC KML version 2.2
(namespace
http://www.opengis.net/kml/2.2). - The following namespaces are also recognized:
http://www.opengis.net/kml/2.0http://www.opengis.net/kml/2.1http://earth.google.com/kml/2.0http://earth.google.com/kml/2.1http://earth.google.com/kml/2.2
Known limitations
- No support for PhotoOverlays.
- No support for cookies and other advanced network support.
- Since:
- 10.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newTLcdKML22ModelDecoderthat is capable of decoding KML files -
Method Summary
Modifier and TypeMethodDescriptionbooleancanDecodeSource(String aSourceName) Checks whether this model decoder can decode the specified data source.Creates a new model from the given data source.A decode method that supplies an additional map of parameters that can be used to query a server.Creates a new model from the given data source.Returns a short, displayable name for the format that is decoded by thisILcdModelDecoder.Returns theorg.xml.sax.ext.EntityResolver2that is used for creating input sources for XSD schemas.Gets the exception handler used by this model decoderReturns theILcdInputStreamFactorythat is used for creating input streams.Gets the resource provider used by this model decoder.Returns thejavax.xml.stream.XMLInputFactorythat is used by this decoder for creatingjavax.xml.stream.XMLStreamReaderinstances.booleanReturns if application schemas are cached.voidsetEntityResolver(EntityResolver2 aEntityResolver) Sets theorg.xml.sax.ext.EntityResolver2to be used for creating input sources for XSD schemas.voidsetExceptionHandler(ILcdExceptionHandler aExceptionHandler) Sets the exception handler to use by this model decoder.voidsetInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory) Sets theILcdInputStreamFactoryto be used for creating input streams.voidsetResourceProvider(TLcdKML22ResourceProvider aResourceProvider) Sets the resource provider this model decoder should use.voidsetUseApplicationSchemaCache(boolean aUseCache) Enables or disables application schema caching depending on the parameter value.voidsetXMLInputFactory(XMLInputFactory aXMLInputFactory) Sets thejavax.xml.stream.XMLInputFactoryto be used by this decoder for creatingjavax.xml.stream.XMLStreamReaderinstances.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.luciad.model.ILcdModelDecoder
canDecodeSource, decodeModelMetadata, decodeModelMetadata, decodeSource, discoverDataSources
-
Constructor Details
-
TLcdKML22ModelDecoder
public TLcdKML22ModelDecoder()Creates a new
TLcdKML22ModelDecoderthat is capable of decoding KML filesThe
TLcdKML22ModelDecoderwill create a resource provider that can be retrieved using the getResourceProvider() method.
-
-
Method Details
-
getDisplayName
Description copied from interface:ILcdModelDecoderReturns a short, displayable name for the format that is decoded by thisILcdModelDecoder.- Returns:
- the displayable name of this
ILcdModelDecoder.
-
canDecodeSource
Description copied from interface:ILcdModelDecoderChecks whether this model decoder can decode the specified data source. It is acceptable for this method to returntruefor a source name whiledecodethrows 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.
- Parameters:
aSourceName- the data source to be verified; typically a file name or a URL.- Returns:
trueif this decoder can likely decode the data specified by the source name,falseotherwise.- See Also:
-
decode
Description copied from interface:ILcdModelDecoderCreates a new model from the given data source.- Parameters:
aSourceName- the data source to be decoded; typically a file name or a URL.- Returns:
- A model containing the decoded data. While
nullis allowed, implementors are advised to throw an error instead. - Throws:
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); } }- See Also:
-
decode
public ILcdModel decode(String aSourceName, InputStream aInputStream, Map<String, String> aExtraParameters) throws IOExceptionA decode method that supplies an additional map of parameters that can be used to query a server.
- Parameters:
aSourceName- The source name of the fileaInputStream- An inputstream that should be usedaExtraParameters- Additional parameters that should be passed to the server- Returns:
- A
TLcdKML22Kml - Throws:
IOException- if the file could not be found or decoded
-
getInputStreamFactory
Description copied from class:ALcdXMLModelDecoderReturns theILcdInputStreamFactorythat is used for creating input streams.- Specified by:
getInputStreamFactoryin interfaceILcdInputStreamFactoryCapable- Specified by:
getInputStreamFactoryin classALcdXMLModelDecoder- Returns:
- the
ILcdInputStreamFactorythat is used for creating input streams. - See Also:
-
setInputStreamFactory
Description copied from class:ALcdXMLModelDecoderSets theILcdInputStreamFactoryto be used for creating input streams. If the configuredentity resolverimplementsILcdInputStreamFactoryCapable, it is also configured with this factory.- Specified by:
setInputStreamFactoryin interfaceILcdInputStreamFactoryCapable- Specified by:
setInputStreamFactoryin classALcdXMLModelDecoder- Parameters:
aInputStreamFactory- the input stream factory to be used by this model decoder.- See Also:
-
getExceptionHandler
Gets the exception handler used by this model decoder- Returns:
- an
ILcdExceptionHandler
-
setExceptionHandler
Sets the exception handler to use by this model decoder.
Not all KML files are properly formatted. KML files can refer to non-existent resources, or have a structure that does not conform to the OGC standard. The exception handler will be informed of such problems. If no
ILcdExceptionHandleris set, the exceptions will be logged to the LuciadLightspeed logging framework.- Parameters:
aExceptionHandler- anILcdExceptionHandler
-
getResourceProvider
Gets the resource provider used by this model decoder.- Returns:
- a
TLcdKML22ResourceProvider
-
setResourceProvider
Sets the resource provider this model decoder should use.
Note that the constructor will already create a resource provider, and this method should not be called unless you want to change the default resource provider
- Parameters:
aResourceProvider- a TLcdKML22ResourceProvider
-
getEntityResolver
Description copied from class:ALcdXMLModelDecoderReturns theorg.xml.sax.ext.EntityResolver2that 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.- Specified by:
getEntityResolverin classALcdXMLModelDecoder- Returns:
- the entity resolver to be used for creating input sources for XSD schemas.
-
getXMLInputFactory
Description copied from class:ALcdXMLModelDecoderReturns thejavax.xml.stream.XMLInputFactorythat is used by this decoder for creatingjavax.xml.stream.XMLStreamReaderinstances.- Specified by:
getXMLInputFactoryin classALcdXMLModelDecoder- Returns:
- the
javax.xml.stream.XMLInputFactorythat is used by this decoder for creatingjavax.xml.stream.XMLStreamReaderinstances.
-
isUseApplicationSchemaCache
public boolean isUseApplicationSchemaCache()Description copied from class:ALcdXMLModelDecoderReturns 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.
- Specified by:
isUseApplicationSchemaCachein classALcdXMLModelDecoder- Returns:
- if application schemas are cached
-
setEntityResolver
Description copied from class:ALcdXMLModelDecoderSets the
org.xml.sax.ext.EntityResolver2to be used for creating input sources for XSD schemas.When the entity resolver is unable to find a schema (i.e. the
resolveEntitymethod returnsnull), theALcdXMLModelDecoder.getInputStreamFactory()is used to create an appropriate input stream for the given system id of the schema.- Specified by:
setEntityResolverin classALcdXMLModelDecoder- Parameters:
aEntityResolver- the entity resolver to be used for creating input sources for XSD schemas.
-
setUseApplicationSchemaCache
public void setUseApplicationSchemaCache(boolean aUseCache) Description copied from class:ALcdXMLModelDecoderEnables or disables application schema caching depending on the parameter value.- Specified by:
setUseApplicationSchemaCachein classALcdXMLModelDecoder- Parameters:
aUseCache- if true, application schema caching is turned on. If false, caching is turned off.
-
setXMLInputFactory
Description copied from class:ALcdXMLModelDecoderSets thejavax.xml.stream.XMLInputFactoryto be used by this decoder for creatingjavax.xml.stream.XMLStreamReaderinstances.- Specified by:
setXMLInputFactoryin classALcdXMLModelDecoder- Parameters:
aXMLInputFactory- thejavax.xml.stream.XMLInputFactoryto be used by this decoder for creatingjavax.xml.stream.XMLStreamReaderinstances.
-
decode
Creates a new model from the given data source.
- Overrides:
decodein classALcdXMLModelDecoder- Parameters:
aSource- the source to read the model from- Throws:
UnsupportedOperationException- in case the decoder is not able to decode from the sourceIOException- See Also:
-