Getting the WMS capabilities
You can find out what the capabilities of a WMS source are by providing its URL to the WmsCapabilities::getCapabilities
WmsCapabilities::getCapabilities
WmsCapabilities::getCapabilities
method.
This is how you request WMS capabilities:
std::string url = "http://sampleservices.luciad.com/wms";
luciad::expected<std::shared_ptr<WmsCapabilities>, ErrorInfo> capabilitiesExpected = WmsCapabilities::getCapabilities(url);
if (capabilitiesExpected.has_value()) {
auto capabilities = capabilitiesExpected.value();
// ...
} else {
ErrorInfo errorInfo = capabilitiesExpected.error();
std::cerr << "Capabilities could not be retrieved from '" << url << "': " << errorInfo.getMessage();
}
string url = "http://sampleservices.luciad.com/wms";
WmsCapabilities capabilities = null;
try
{
capabilities = WmsCapabilities.GetCapabilities(url);
//...
}
catch (IOException exception)
{
Console.Error.WriteLine("Capabilities could not be retrieved on '" + url + "': " + exception.Message);
}
String url = "http://sampleservices.luciad.com/wms";
WmsCapabilities capabilities = null;
try {
capabilities = WmsCapabilities.getCapabilities(url);
} catch (Exception exception) {
Log.e("LUCIAD", "Capabilities could not be retrieved on '" + url + "': " + exception.getMessage());
}
Once you have the capabilities data, you can inspect it to customize the request for the creation of the WMS model.
If an error occurs during the capabilities retrieval, you can inspect the returned object to learn the reason of the error.
Decoding WMS data to a model
You create a model with the WmsModelDecoder::decode
WmsModelDecoder::decode
WmsModelDecoder::decode
method.
This is how you set up a model for WMS data:
std::shared_ptr<WmsDataSource> dataSource = WmsDataSource::newBuilder().url(url).addLayer("rivers").addLayer("cities", "default").build();
luciad::expected<std::shared_ptr<IRasterModel>, ErrorInfo> expModel = WmsModelDecoder::decode(dataSource, capabilities);
if (expModel.has_value()) {
// ...
} else {
ErrorInfo errorInfo = expModel.error();
std::cerr << "could not be decoded: " << errorInfo.getMessage();
}
try
{
WmsDataSource dataSource = WmsDataSource.NewBuilder()
.Url(url)
.AddLayer("rivers")
.AddLayer("cities", "default")
.Build();
var rasterModel = WmsModelDecoder.Decode(dataSource, capabilities);
// ...
}
catch (IOException exception)
{
Console.Error.WriteLine("Failed to open WMS data source for '" + url + "': " + exception.Message);
}
try {
WmsDataSource dataSource = WmsDataSource.newBuilder()
.url(url)
.addLayer("rivers")
.addLayer("cities", "default")
.build();
IRasterModel rasterModel = WmsModelDecoder.decode(dataSource, capabilities);
// ...
} catch (Exception exception) {
Log.e("LUCIAD", "Failed to open WMS data source for '" + url + "': " + exception.getMessage());
}
The result is a model created from the URL you specified as a parameter.
If you already requested the WMS capabilities, you can specify them as a parameter, and prevent the need for a new query.
If you don’t specify the WMS capabilities, they’re retrieved automatically.
Within the data source, you select a layer and a style for that layer.
You can discover which layer information to use through WmsCapabilities::getCapabilities
WmsCapabilities::getCapabilities
WmsCapabilities::getCapabilities
.
The code in Program: creating a WMS model:
-
Configures the data source to select two layers. The
cities
layer is on top of therivers
layer. You can discover the layer information programmatically usingWmsCapabilities::getCapabilities
WmsCapabilities::getCapabilities
WmsCapabilities::getCapabilities
.+The URL is a required parameter, and you must select at least one layer.
-
Calls the
rivers
layer without any specific style. The default style offered by the WMS is used for this layer. -
Selects a specific style for the
cities
layer: thedefault
style. -
Uses the capabilities retrieved in the Program: requesting WMS capabilities snippet to prevent another
GetCapabilities
request to the WMS server.
The capabilities are used to cross-check the availability of data requested in the WmsDataSource
WmsDataSource
WmsDataSource
, and to find the defaults for unavailable values.
See Visualizing Raster Data for more information about visualizing raster data.
Limitations
The support for the OGC WMS protocol has some limitations. For details, see
the WmsModelDecoder::decode
WmsModelDecoder::decode
WmsModelDecoder::decode
method documentation.