Introduction to the WFS API

Edited

This article is a brief introduction to the main uses of the WFS, or Web Feature Service, API. If you are already familiar with APIs and the WFS API, you can directly access the WFS documentation. Otherwise, read on for more details.

An API, or Application Programming Interface, is a tool designed to enable different software systems to communicate with each other. If you want to use data stored somewhere online, the purpose of an API is to allow you to interact with that data in a way that the source understands. And if you want to share your data with others, an API allows you to define the type of access they have.

Opendatasoft provides several different APIs to interact with the platform, but the Opendatasoft WFS API gives you access to the public geographic data on the Opendatasoft platform.

What the WFS API allows you to do

To interact with the API, you perform a so-called API call. A call is when you visit the appropriate URL, with the request you're making specified in the URL. The API then retrieves that information and returns it to your browser.

By including one of the following commands in bold into the API call, the WFS API allows you to perform three main actions:

  • GetCapabilities: Retrieves the metadata of the WFS service.

  • DescribeFeatureType: Generates a description of the schema for the supported feature types by the service.

  • GetFeature: Retrieves the data from a dataset and renders it using the GML representation.

See the section below for each for an example of the proper syntax to use.

The examples on this page are based on a dataset of European countries and their ratings for gender equality. And to visualize the data, we'll use QGIS, a popular application for viewing, displaying, and analyzing geospatial data.

GetCapabilities

GetCapabilities is one of the three main actions you can perform with the WFS API. This action lists the datasets within a domain and its associated features.

It has two required parameters:

  • Service: "WFS"

  • Request: "GetCapabilities"

The URL for this request is therefore: https://documentation-resources.opendatasoft.com/api/wfs?service=wfs&request=getcapabilities

The "FeatureTypeList" section shows the available datasets within the domain:

DescribeFeatureType

This action mainly allows you to describe the schema of a dataset based on its typename.

In WFS, the "typename" is a dataset's identifier. In the example from GetCapabilities above, one of the datasets in the "documentation-resources" workspace had the typename: "ods:gender-equality-in-europe." We'll use it in the example below.

This action has four required parameters:

  • Service: "WFS"

  • Request: "DescribeFeatureType"

  • Version: "2.0.0"

  • Typename: "ods:gender-equality-in-europe"

The URL for this request is therefore: https://documentation-resources.opendatasoft.com/api/wfs?service=wfs&request=describefeaturetype&version=2.0.0&typename=ods:gender-equality-in-europe

As you can see in the image, the elements listed by this request are "country," "country_zip," "general_index," and so on. These correspond to the columns in the "ods:gender-equality-in-europe" dataset.

GetFeature

This operation primarily allows you to retrieve the data from a dataset based on its typename. Remember that in WFS, the "typename" is a dataset's identifier.

It has four required parameters:

  • Service: "WFS"

  • Request: "GetFeature"

  • Version: "2.0.0"

  • Typename: "ods:gender-equality-in-europe"

The URL for this request is therefore: https://documentation-resources.opendatasoft.com/api/wfs?service=wfs&request=getfeature&version=2.0.0&typename=ods:gender-equality-in-europe

So the elements returned by this request correspond to the data within the "ods:gender-equality-in-europe" dataset. Each row in the dataset corresponds to a member (<wfs:member>).

An example of using the WFS API from QGIS

A common usage is to generate an interesting visualization of our data using geographic visualization software such as QGIS, ArcGIS, MapInfo Professional, GRASS GIS, etc.

  1. ​Open the Data Source Manager​, add an OpenStreetMap layer, then create a new WFS connection

  1. Add the URL to your domain followed by /api/wfs, use version 2.0.0

  1. Add the dataset as a layer

  1. Edit the properties to add a gradient and adjust its reference column

  1. Use, interpret, explore and share your visualization

Here, we have specified to the software the significant column general_index for the gradient, which represents the average rating given to a country. Thus, we have a better representation of gender inequalities in Europe compared to a tabular view.

What next?

Hopefully this page helps explain how the WFS API can be useful to you.

Using an API is perhaps not for everyone. However, with a little effort, the API can help you better understand and efficiently use your own data as well as other public data.

To assist you along the way, we invite you to dive into our documentation for the WFS API.