@LcdService(service=ILcdModelDecoder.class, priority=20000) public class TLcdKML22ModelDecoder extends ALcdXMLModelDecoder
ILcdModel
objects.
File | Required | Entry point | Description |
---|---|---|---|
*.kml | x | A KML file | |
*.kmz | x | Zip archive containing a KML (.kml) file and possibly other resources |
inputStreamFactory
of this decoder.TLcdKML22Kml
model per KML file.TLcdKML22Kml
instances) returned by this model decoder implement
ILcdModelTreeNode
,ILcd2DBoundsIndexedModel
and ILcdIntegerIndexedModel
.TLcdKML22Kml
has a hierarchical structure, which is organized in accordance with
the KML file.
The following model implementations can be encountered in the KML model hierarchy:
KML container type | LuciadLightspeed KML class | Implemented LuciadLightspeed interfaces |
---|---|---|
KML | TLcdKML22Kml |
ILcdModelTreeNode, ILcd2DBoundsIndexedModel, ILcdIntegerIndexedModel |
Abstract container | TLcdKML22AbstractContainer |
ILcdModelTreeNode, ILcd2DBoundsIndexedModel, ILcdIntegerIndexedModel |
Document | TLcdKML22Document |
ILcdModelTreeNode, ILcd2DBoundsIndexedModel, ILcdIntegerIndexedModel |
Folder | TLcdKML22Folder |
ILcdModelTreeNode, ILcd2DBoundsIndexedModel, ILcdIntegerIndexedModel |
Network Link | TLcdKML22NetworkLink |
ILcdModelTreeNode |
<kml>
<document>
<folder>
<placemark>...</placemark>
</folder>
</document>
</kml>
will be decoded into the following model hierarchy:
TLcdKML22Kml (implements ILcdModelTreeNode)
|
+-- TLcdKML22Document (implements ILcdModelTreeNode)
|
+ TLcdKML22Folder (implements ILcdModelTreeNode) -> has placemark element.
TLcdKML22ModelDescriptor
.TLcdGeodeticReference
, WGS84.KML type | LuciadLightspeed KML class | Implemented LuciadLightspeed interfaces |
---|---|---|
Placemark | TLcdKML22Placemark |
ILcdShapeList |
Ground overlay | TLcdKML22GroundOverlay |
ILcdBounded |
Screen overlay | TLcdKML22ScreenOverlay |
|
Photo overlay | TLcdKML22PhotoOverlay |
ILcdBounded |
DAE (3D) model | TLcdKML223DModel |
ILcdBounded |
TLcdKML22Kml
instance) needs to be wrapped in a
TLcdKML22DynamicModel
. This model will resolve and include dynamic contents
on-the-fly.TLcdKMl22DynamicModel
can
be wrapped in a TLcdKML22RenderableModel
. This model will flatten the model
hierarchy of a TLcdKML22Kml
and make sure all objects are processed (via either
applyOnInteract
or elements
in the right order. //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);
Decoding and visualizing KML data on a GXY 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
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);
http://www.opengis.net/kml/2.2
).http://www.opengis.net/kml/2.0
http://www.opengis.net/kml/2.1
http://earth.google.com/kml/2.0
http://earth.google.com/kml/2.1
http://earth.google.com/kml/2.2
Constructor and Description |
---|
TLcdKML22ModelDecoder()
Creates a new
TLcdKML22ModelDecoder that is capable of decoding KML files |
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.
|
ILcdModel |
decode(String aSourceName,
InputStream aInputStream,
Map<String,String> aExtraParameters)
A decode method that supplies an additional map of parameters that can be used to query a server.
|
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. |
ILcdExceptionHandler |
getExceptionHandler()
Gets the exception handler used by this model decoder
|
ILcdInputStreamFactory |
getInputStreamFactory()
Returns the
ILcdInputStreamFactory that is used for creating input streams. |
TLcdKML22ResourceProvider |
getResourceProvider()
Gets the resource provider used by this model decoder.
|
XMLInputFactory |
getXMLInputFactory()
Returns the
javax.xml.stream.XMLInputFactory that is used by this decoder for creating
javax.xml.stream.XMLStreamReader instances. |
boolean |
isUseApplicationSchemaCache()
Returns if application schemas are cached.
|
void |
setEntityResolver(EntityResolver2 aEntityResolver)
Sets the
org.xml.sax.ext.EntityResolver2 to be used for creating input sources for
XSD schemas. |
void |
setExceptionHandler(ILcdExceptionHandler aExceptionHandler)
Sets the exception handler to use by this model decoder.
|
void |
setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
Sets the
ILcdInputStreamFactory to be used for creating input streams. |
void |
setResourceProvider(TLcdKML22ResourceProvider aResourceProvider)
Sets the resource provider this model decoder should use.
|
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. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canDecodeSource, decodeModelMetadata, decodeModelMetadata, decodeSource, discoverDataSources
public TLcdKML22ModelDecoder()
Creates a new TLcdKML22ModelDecoder
that is capable of decoding KML files
The TLcdKML22ModelDecoder
will create a resource provider that can be retrieved
using the getResourceProvider() method.
public String getDisplayName()
ILcdModelDecoder
ILcdModelDecoder
.ILcdModelDecoder
.public 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 ILcdModel decode(String aSourceName, InputStream aInputStream, Map<String,String> aExtraParameters) throws IOException
A decode method that supplies an additional map of parameters that can be used to query a server.
aSourceName
- The source name of the fileaInputStream
- An inputstream that should be usedaExtraParameters
- Additional parameters that should be passed to the serverTLcdKML22Kml
IOException
- if the file could not be found or decodedpublic 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 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 ILcdExceptionHandler getExceptionHandler()
ILcdExceptionHandler
public void setExceptionHandler(ILcdExceptionHandler aExceptionHandler)
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 ILcdExceptionHandler
is set, the exceptions will be logged to the LuciadLightspeed logging framework.
aExceptionHandler
- an ILcdExceptionHandler
public TLcdKML22ResourceProvider getResourceProvider()
TLcdKML22ResourceProvider
public void setResourceProvider(TLcdKML22ResourceProvider aResourceProvider)
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
aResourceProvider
- a TLcdKML22ResourceProviderpublic 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 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 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)
ALcdXMLModelDecoder
javax.xml.stream.XMLInputFactory
to be used by this decoder for creating
javax.xml.stream.XMLStreamReader
instances.setXMLInputFactory
in class ALcdXMLModelDecoder
aXMLInputFactory
- the javax.xml.stream.XMLInputFactory
to be used by this decoder
for creating javax.xml.stream.XMLStreamReader
instances.public ILcdModel decode(Source aSource) throws IOException
Creates a new model from the given data source.
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)