Getting the WMS capabilities

You can find out what the capabilities of a WMS source are by providing its URL to the WmsCapabilities::getCapabilitiesWmsCapabilities::getCapabilitiesWmsCapabilities::getCapabilities method. This is how you request WMS capabilities:

Program: Requesting 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::decodeWmsModelDecoder::decodeWmsModelDecoder::decode method. This is how you set up a model for WMS data:

Program: Creating a WMS model
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::getCapabilitiesWmsCapabilities::getCapabilitiesWmsCapabilities::getCapabilities.

The capabilities are used to cross-check the availability of data requested in the WmsDataSourceWmsDataSourceWmsDataSource, 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::decodeWmsModelDecoder::decodeWmsModelDecoder::decode method documentation.