Getting the WFS capabilities
You can find out what the capabilities of a WFS source are by providing its URL to the WfsCapabilities::getCapabilitiesWfsCapabilities::getCapabilitiesWfsCapabilities::getCapabilities method.
This is how you request the WFS capabilities:
const std::string url = "https://sampleservices.luciad.com/wfs";
expected<std::shared_ptr<WfsCapabilities>, ErrorInfo> expCapabilities = WfsCapabilities::getCapabilities(url);
if (expCapabilities.has_value()) {
const std::shared_ptr<WfsCapabilities>& wfsCapabilities = expCapabilities.value();
std::vector<std::shared_ptr<WfsFeatureType>> featureTypes = wfsCapabilities->getFeatureTypes();
// ...
} else {
const ErrorInfo& errorInfo = expCapabilities.error();
std::cerr << "Capabilities could not be retrieved from '" << url << "': " << errorInfo.getMessage() << std::endl;
}
string url = "https://sampleservices.luciad.com/wfs";
try
{
wfsCapabilities = WfsCapabilities.GetCapabilities(url);
//...
}
catch (IOException exception)
{
Console.Error.WriteLine("Capabilities could not be retrieved on '" + url + "': " + exception.Message);
}
String url = "https://sampleservices.luciad.com/wfs";
try {
wfsCapabilities = WfsCapabilities.getCapabilities(url);
List<WfsFeatureType> featureTypes = wfsCapabilities.getFeatureTypes();
// ...
} catch (IOException exception) {
Log.e("WFS", "Failed to open WFS capabilities for '" + url + "': " + exception.getMessage());
}
Once you have the capabilities data, you can inspect it to customize the request for the creation of the WFS model.
If an error occurs during the capabilities retrieval, you can inspect the returned object to learn the reason of the error.
Decoding WFS data to a model
You create a model with the WfsModelDecoder::decodeWfsModelDecoder::decodeWfsModelDecoder::decode method.
This is how you set up a model for WFS data:
const std::shared_ptr<WfsDataSource> dataSource = WfsDataSource::newBuilder().url(url).featureType("ns4:t_cities__c__1214").build();
expected<std::shared_ptr<IFeatureModel>, ErrorInfo> expModel = WfsModelDecoder::decode(dataSource, wfsCapabilities);
if (expModel.has_value()) {
// ...
} else {
const ErrorInfo& errorInfo = expModel.error();
std::cerr << "Could not decode the WFS data source: " << errorInfo.getMessage() << std::endl;
}
try
{
WfsDataSource dataSource = WfsDataSource.NewBuilder()
.Url(url)
.FeatureType("ns4:t_cities__c__1214")
.Build();
var featureModel = WfsModelDecoder.Decode(dataSource, wfsCapabilities);
// ...
}
catch (Exception exception)
{
Console.Error.WriteLine("Failed to open WFS data source for '" + url + "': " + exception.Message);
}
try {
WfsDataSource dataSource = WfsDataSource.newBuilder().url(url).featureType("ns4:t_cities__c__1214").build();
IFeatureModel model = WfsModelDecoder.decode(dataSource, wfsCapabilities);
// ...
} catch (IOException exception) {
Log.e("WFS", "Could not decode the WFS data source: " + exception.getMessage());
}
The result is a model created from the URL you specified as a parameter.
If you already requested the WFS capabilities, you can specify them as a parameter, and prevent the need for a new query.
If you don’t specify the WFS capabilities, they’re retrieved automatically.
Within the data source, you select a feature type.
You can discover which feature types are offered through WfsCapabilities::getCapabilitiesWfsCapabilities::getCapabilitiesWfsCapabilities::getCapabilities.
The code in Program: creating a WFS model:
-
Configures the data source to select a feature type. You can discover the available feature types information programmatically using
WfsCapabilities::getCapabilitiesWfsCapabilities::getCapabilitiesWfsCapabilities::getCapabilities.The URL is a required parameter, and you must select at least one feature type.
-
Uses the capabilities retrieved in the Program: requesting WFS capabilities snippet to prevent another
GetCapabilitiesrequest to the WFS server.
The capabilities are used to cross-check the availability of data requested in the WfsDataSourceWfsDataSourceWfsDataSource, and to find the defaults for unavailable values.
See Visualizing Feature Data for more information about visualizing and styling vector data.
Requesting a specific output format
By default, LuciadCPillar sends no OUTPUTFORMAT parameter, so the WFS server returns data in its default GML format.
You can request a different format, for example GeoJSON, through the outputFormat option on WfsModelDecoderOptionsWfsModelDecoderOptionsWfsModelDecoderOptions.
The output formats advertised by a feature type are available through WfsFeatureType::getOutputFormatsWfsFeatureType::getOutputFormatsWfsFeatureType::getOutputFormats, so you can read an output format from the capabilities and pass it back.
When the capabilities list no formats for a feature type, that method returns the formats the server advertises for its GetFeature operation instead.
Those apply to every feature type, and some servers advertise formats only there.
This is how you request a specific output format:
const std::shared_ptr<WfsFeatureType>& featureType = wfsCapabilities->getFeatureTypes()[0];
const std::vector<std::string>& outputFormats = featureType->getOutputFormats();
auto jsonIt = std::ranges::find(outputFormats, "application/json");
if (jsonIt != outputFormats.end()) {
WfsModelDecoderOptions options = WfsModelDecoderOptions::newBuilder().outputFormat(*jsonIt).build();
auto model = WfsModelDecoder::decode(dataSource, options, wfsCapabilities);
// ...
}
WfsFeatureType featureType = wfsCapabilities.FeatureTypes[0];
var outputFormats = featureType.OutputFormats;
if (outputFormats.Contains("application/json"))
{
WfsModelDecoderOptions options = WfsModelDecoderOptions.NewBuilder()
.OutputFormat("application/json")
.Build();
var featureModel = WfsModelDecoder.Decode(dataSource, options, wfsCapabilities);
// ...
}
WfsFeatureType featureType = wfsCapabilities.getFeatureTypes().get(0);
List<String> outputFormats = featureType.getOutputFormats();
if (outputFormats.contains("application/json")) {
WfsModelDecoderOptions options = WfsModelDecoderOptions.newBuilder().outputFormat("application/json").build();
IFeatureModel model = WfsModelDecoder.decode(dataSource, options, wfsCapabilities);
// ...
}
|
A value that looks like JSON, such as |
Limitations
The support for the OGC WFS protocol has some limitations. For details, see
the WfsModelDecoder::decodeWfsModelDecoder::decodeWfsModelDecoder::decode
method documentation.