Class TLcdOGCWMSProxyModelDecoder
- All Implemented Interfaces:
ILcdDataSourceModelDecoder
,ILcdModelDecoder
ILcdModelDecoder
implementation that allows to access a WMS
server and retrieve data from it.
Input
- An instance of
TLcdWMSDataSource
, containing a WMS base URL and one or more WMS layer identifiers. - A String referring to the WMS base URL.
- A String referring to the WMS base URL and a layer identifier, specified as a
data=layerName
key/value pair.
Supported transfer protocols
- http
- https
Model structure
Thedecode(String)
and decodeSource(com.luciad.model.ILcdDataSource)
methods returns an ILcdModel
containing one ALcdWMSProxy
element. This element can be used to
access the capabilities of the OGC WMS server, and to configure the layer data to be retrieved
(if not yet set through the input supplied to this decoder).
The returned model is also an ILcdMultiDimensionalModel
,
with support for OGC WMS dimensions time, elevation, depth and altitude.
If a WMS layer is registered on the ALcdWMSProxy
that defines one
of more of these dimensions, they are automatically picked up by the model.
Model descriptor
All models returned by this decoder have aTLcdWMSProxyModelDescriptor
.
Model reference
All models returned by this model decoder have WGS84 as reference. The actual model reference that is best used for requesting images from the WMS depends on the WMS layers that are configured within theALcdWMSProxy
object.
Model elements
The model contains a singleALcdWMSProxy
object.
This object can be configured for the actual WMS layers one is interested in.
When the model is decoded just using a URL the ALcdWMSProxy
is configured with the first WMS layer
found in the capabilities. This behavior can be switched off by passing an argument within the constructor.
Thread safety
- The decoding of models is thread-safe, as long as no properties are changed during the decoding.
- The decoded models are thread-safe for read access.
Sample code
Decoding a WMS data source:
String serverURL = "https://sampleservices.luciad.com/wms";
String wmsLayerName = "cities";
//Create the data source
TLcdWMSDataSource dataSource = TLcdWMSDataSource.newBuilder()
.uri(serverURL)
.addLayer(wmsLayerName)
.build();
//Decode the model
ILcdModelDecoder decoder = new TLcdOGCWMSProxyModelDecoder();
ILcdModel model = decoder.decodeSource(dataSource);
Decoding a string containing the server URL and WMS layer
String serverURL = "https://sampleservices.luciad.com/wms";
String wmsLayerName = "cities";
//Concat the url and layer name to a single string
String sourceName = String.format("%s?data=%s", serverURL, wmsLayerName);
//Decode the model
ILcdModelDecoder decoder = new TLcdOGCWMSProxyModelDecoder();
ILcdModel model = decoder.decode(sourceName);
- See Also:
-
Constructor Summary
ConstructorDescriptionCreates a newTLcdOGCWMSProxyModelDecoder
instance.TLcdOGCWMSProxyModelDecoder
(TLcdDataModel[] aSLDDataModels) Creates a newTLcdOGCWMSProxyModelDecoder
instance, configured with the given SLD extension data models.TLcdOGCWMSProxyModelDecoder
(ILcdOWSTransport aTransport, TLcdDataModel[] aSLDDataModels) Creates a newTLcdOGCWMSProxyModelDecoder
instance, configured with the given transport and SLD extension data models. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAdditionalXYWorldReferenceFormatter
(ILcdXYWorldReferenceFormatter aXYWorldReferenceFormatter) Adds additional formatters forILcdXYWorldReference
objects onto a string representation.boolean
canDecodeSource
(ILcdDataSource aDataSource) Checks whether this model decoder can decode the data source(s), identified by the passedILcdDataSource
.boolean
canDecodeSource
(String aServerURLAsString) Checks whether this model decoder can decode the specified data source.decode
(TLcdWMSClient aClient) Creates anILcdModel
containing oneALcdWMSProxy
element, which can be used to access the specified WMS server.Creates anILcdModel
containing oneALcdWMSProxy
element, which can be used to access the specified WMS server.decodeSource
(ILcdDataSource aDataSource) This method supports decoding aTLcdWMSDataSource
and aTLcdDataSource
.Returns a short, displayable name for the format that is decoded by thisILcdModelDecoder
.Deprecated.This method has been kept for compatibility reasons with LuciadMap.boolean
Returns whether the decoder returns a model containing an emptywms proxy
object.boolean
Returns whether XML validation is enabled for the XML capabilities document provided by a server.void
setEntityLocation
(String aSystemEntity, URL aEntityURL) Sets the URL to be used for an entity defined in the WMS capabilities document provided by a server.void
setRequestProperty
(String aKey, String aValue) Sets the general request property.void
setSAXParser
(String aSAXParser) Deprecated.This method has been kept for compatibility reasons with LuciadMap.void
setUseEmptyProxyForUrlOnly
(boolean aUseEmptyProxyForUrlOnly) Sets the new value for how the model is constructed in case only a URL is provided.void
setValidating
(boolean aValidating) Specifies whether XML validation (DTD and XML Schema) is enabled for the WMS capabilities document provided by a server.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.luciad.model.ILcdModelDecoder
decodeModelMetadata, decodeModelMetadata, discoverDataSources
-
Constructor Details
-
TLcdOGCWMSProxyModelDecoder
public TLcdOGCWMSProxyModelDecoder()Creates a newTLcdOGCWMSProxyModelDecoder
instance. -
TLcdOGCWMSProxyModelDecoder
Creates a newTLcdOGCWMSProxyModelDecoder
instance, configured with the given SLD extension data models.SLD extension data models are needed if the client wants to submit an SLD to the WMS that uses an extension of the OGC SLD specification. For instance, if a custom symbolizer is introduced to address specific styling requirements. The data models of such extensions are needed to be able to encode any configured SLD (see
ALcdWMSProxy.setStyledLayerDescriptor(com.luciad.wms.sld.model.TLcdSLDStyledLayerDescriptor)
) to XML, for embedding in requests.- Parameters:
aSLDDataModels
- a list of SLD extension data models
-
TLcdOGCWMSProxyModelDecoder
Creates a newTLcdOGCWMSProxyModelDecoder
instance, configured with the given transport and SLD extension data models.SLD extension data models are needed if the client wants to submit an SLD to the WMS that uses an extension of the OGC SLD specification. For instance, if a custom symbolizer is introduced to address specific styling requirements. The data models of such extensions are needed to be able to encode any configured SLD (see
ALcdWMSProxy.setStyledLayerDescriptor(com.luciad.wms.sld.model.TLcdSLDStyledLayerDescriptor)
) to XML, for embedding in requests.- Parameters:
aTransport
- The transport. Must not be null. The transport will be used when decoding the model, except when you call thedecode(TLcdWMSClient)
method directly.aSLDDataModels
- a list of SLD extension data models. Usenull
or an empty array when no extensions are needed.- Since:
- 2018.0
-
-
Method Details
-
getDisplayName
Description copied from interface:ILcdModelDecoder
Returns a short, displayable name for the format that is decoded by thisILcdModelDecoder
.- Specified by:
getDisplayName
in interfaceILcdModelDecoder
- Returns:
- the displayable name of this
ILcdModelDecoder
.
-
setRequestProperty
Sets the general request property. If a property with the key already exists, overwrite its value with the new value.- Parameters:
aKey
- the keyword by which the request is known (e.g., "accept
").aValue
- the value associated with it.- See Also:
-
setEntityLocation
Sets the URL to be used for an entity defined in the WMS capabilities document provided by a server. Multiple mappings can be provided, but only one location per entity. If no locations are specified, the original entity locations defined in the XML document are used. If a location for an entity already exists, it is replaced with the new location. By specifyingnull
as location for an entity, a previously specified location can be removed. A typical example of an entity definition in an XML document is a reference to a DTD or XML Schema. By using this method, one can replace such a reference with a reference to a locally stored copy of the DTD or XML Schema.- Parameters:
aSystemEntity
- The entity to be relocated.aEntityURL
- The URL to be used for a given entity.
-
setValidating
public void setValidating(boolean aValidating) Specifies whether XML validation (DTD and XML Schema) is enabled for the WMS capabilities document provided by a server. By default, this value is set tofalse
.- Parameters:
aValidating
- Whether XML validation should be enabled.
-
isValidating
public boolean isValidating()Returns whether XML validation is enabled for the XML capabilities document provided by a server. By default, this value is set tofalse
.- Returns:
- True if XML validation is enabled.
-
isUseEmptyProxyForUrlOnly
public boolean isUseEmptyProxyForUrlOnly()Returns whether the decoder returns a model containing an emptywms proxy
object. The default value isfalse
. When decoding using a URL only the model returned by the decoder contains awms proxy
which is configured with one WMS layer such that you get a proper visualization of the WMS layer. When the value istrue
thewms proxy
object within the model is not configured with any of the layers served by the WMS service. In this case you need to configure the layers you want yourself or nothing will be displayed on the map for this model.- Returns:
- whether the decoder returns a model containing an empty
wms proxy
object. - Since:
- 2021.0
-
setUseEmptyProxyForUrlOnly
public void setUseEmptyProxyForUrlOnly(boolean aUseEmptyProxyForUrlOnly) Sets the new value for how the model is constructed in case only a URL is provided.- Parameters:
aUseEmptyProxyForUrlOnly
- the new value for how the model is constructed in case only a URL is provided.- Since:
- 2021.0
- See Also:
-
addAdditionalXYWorldReferenceFormatter
public void addAdditionalXYWorldReferenceFormatter(ILcdXYWorldReferenceFormatter aXYWorldReferenceFormatter) Adds additional formatters forILcdXYWorldReference
objects onto a string representation.- Parameters:
aXYWorldReferenceFormatter
- additional formatter.
-
setSAXParser
Deprecated.This method has been kept for compatibility reasons with LuciadMap. The methodSAXParserFactory.newInstance()
is now used to create a SAX parser.Sets the SAXParser used by the TLcdOGCWMSProxyModelDecoder.- Parameters:
aSAXParser
- the new SAXParser class name.- See Also:
-
getSAXParser
Deprecated.This method has been kept for compatibility reasons with LuciadMap. The methodSAXParserFactory.newInstance()
is now used to create a SAX parser.Returns the SAXParser used by the TLcdOGCWMSProxyModelDecoder.- Returns:
- the SAXParser used by the TLcdOGCWMSProxyModelDecoder.
- See Also:
-
canDecodeSource
Description copied from interface:ILcdModelDecoder
Checks whether this model decoder can decode the specified data source. It is acceptable for this method to returntrue
for a source name whiledecode
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.
- Specified by:
canDecodeSource
in interfaceILcdModelDecoder
- Parameters:
aServerURLAsString
- the data source to be verified; typically a file name or a URL.- Returns:
true
if this decoder can likely decode the data specified by the source name,false
otherwise.- See Also:
-
decode
Creates anILcdModel
containing oneALcdWMSProxy
element, which can be used to access the specified WMS server. TheALcdWMSProxy
object contained in the returned model has the following properties:- The methods
ALcdWMSProxy.createImageInputStream(int, int, com.luciad.view.ILcdXYWorldReference, com.luciad.shape.ILcdBounds, java.awt.Color)
andALcdWMSProxy.createImage(int, int, com.luciad.view.ILcdXYWorldReference, com.luciad.shape.ILcdBounds, java.awt.Color)
, which are used to send GetMap requests, are thread-safe. Multiple threads can use these methods concurrently on the sameALcdWMSProxy
object, without the need for extra synchronization. - The method
ALcdWMSProxy.clone()
returns a shallow clone, except for the internal data structures that are used to store the additional parameters, request properties, entity locations, reference formatters and styled named layer wrappers: these structures are cloned (not their contents), allowing to set different configuration parameters on the cloned object than on the source object. The capabilities itself are not cloned.
aSourceName
the source to be decoded, can be a formatted asURI?data=LayerName
to identify the server URI and layer name.-
If you only provide the server URI, it returns a
model
which is configured with the first layer found in the WMS capabilities unless this decoder's propertyisUseEmptyProxyForUrlOnly()
returnstrue
. -
If you provide both URI and layer name, it returns a
model
with the specified layer data.
- Specified by:
decode
in interfaceILcdModelDecoder
- Parameters:
aSourceName
- The URL of the WMS server.- Returns:
- an
ILcdModel
with aALcdWMSProxy
element. - Throws:
TLcdOGCWMSServiceException
- when the server sends a service exception report.TLcdOGCWMSHttpException
- when a HTTP error is received.TLcdOGCWMSException
- in all other cases.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:
- The methods
-
decode
Creates anILcdModel
containing oneALcdWMSProxy
element, which can be used to access the specified WMS server. TheALcdWMSProxy
object contained in the returned model has the following properties:- The methods
ALcdWMSProxy.createImageInputStream(int, int, com.luciad.view.ILcdXYWorldReference, com.luciad.shape.ILcdBounds, java.awt.Color)
andALcdWMSProxy.createImage(int, int, com.luciad.view.ILcdXYWorldReference, com.luciad.shape.ILcdBounds, java.awt.Color)
, which are used to send GetMap requests, are thread-safe. Multiple threads can use these methods concurrently on the sameALcdWMSProxy
object, without the need for extra synchronization. - The method
ALcdWMSProxy.clone()
returns a shallow clone, except for the internal data structures that are used to store the additional parameters, request properties, entity locations, reference formatters and styled named layer wrappers: these structures are cloned (not their contents), allowing to set different configuration parameters on the cloned object than on the source object. The capabilities itself are not cloned. The WMS client will not be cloned.
- Parameters:
aClient
- TheTLcdWMSClient
which will be used to perform all requests in theALcdWMSProxy
- Returns:
- an
ILcdModel
with aALcdWMSProxy
element. - Throws:
TLcdOGCWMSServiceException
- when the server sends a service exception report.TLcdOGCWMSHttpException
- when a HTTP error is received.TLcdOGCWMSException
- in all other cases.IOException
- The methods
-
canDecodeSource
Description copied from interface:ILcdModelDecoder
Checks whether this model decoder can decode the data source(s), identified by the passed
ILcdDataSource
.For performance reasons, we strongly recommend that this will only be a simple test. For example: check the instance class of
aDataSource
, or check the file extension if it is aTLcdDataSource
.The default implementation of this method will check if the given
ILcdDataSource
is aTLcdDataSource
. If not, this method returns false. Otherwise, it delegates the source to theILcdModelDecoder.canDecodeSource(String)
method.- Specified by:
canDecodeSource
in interfaceILcdModelDecoder
- Parameters:
aDataSource
- theILcdModelSource
to be verified.- Returns:
true
if this decoder can likely decode the data specified byaDataSource
,false
otherwise.- See Also:
-
decodeSource
This method supports decoding aTLcdWMSDataSource
and aTLcdDataSource
. The latter data source behaves the same as calling the methoddecode(String)
.The minimum requirements for the
TLcdWMSDataSource
is the availability of the WMS server URI and one or more layers. Other values are optional and defaults are chosen.Mandatory information that has to be correct in the data source is the following.
- WMS server URI.
- The names of the layers. If the name of a layer is not offered by the WMS server the decoding fails.
For the optional information the decoding is more lenient.
- Layer with invalid style reference: The default style is used as fall-back.
- Layer with queryable set to
true
when the server does not support querying for that layer. The querying is switched off to honour the capabilities of the server. - Invalid map format: the PNG format is used as default, if the server supports it, otherwise JPEG.
- Specified by:
decodeSource
in interfaceILcdModelDecoder
- Parameters:
aDataSource
- theILcdDataSource
to be decoded.- Returns:
- the model containing the WMS proxy object.
- Throws:
IOException
- when decoding the data source fails.- See Also:
-