Connect to a WFS service

A Web Feature Service (WFS) is a web service for querying spatial data that has a standardized API that is defined by the Open Geospatial Consortium (OGC). The WfsClient class in the spatial IO module lets developers connect to a WFS service and query data from the service.

The following features are supported by the WfsClient class:

  • Supported versions: 1.0.0, 1.1.0, and 2.0.0

  • Supported filter operators: binary comparisons, logic, math, value, and bbox.

  • Requests are made using HTTP GET only.

  • Supported operations:

    Operation Description
    GetCapabilities Generates a metadata document with valid WFS operations and parameters
    GetFeature Returns a selection of features from a data source
    DescribeFeatureType Returns the supported feature types

Using the WFS client

The class in the spatial IO module makes it easy to query a WFS service and convert the responses into GeoJSON objects. This GeoJSON object can then be used for other mapping purposes.

The following code queries a WFS service and renders the returned features on the map.

Supported filters

The specification for the WFS standard makes use of OGC filters. The filters below are supported by the WFS client, assuming that the service being called also supports these filters. Custom filter strings can be passed into the CustomFilter class.

Logical operators

  • And
  • Or
  • Not

Value operators

  • GmlObjectId
  • ResourceId

Math operators

  • Add
  • Sub
  • Mul
  • Div

Comparison operators

  • PropertyIsEqualTo
  • PropertyIsNotEqualTo
  • PropertyIsLessThan
  • PropertyIsGreaterThan
  • PropertyIsLessThanOrEqualTo
  • PropertyIsGreaterThanOrEqualTo
  • PropertyIsLike
  • PropertyIsNull
  • PropertyIsNil
  • PropertyIsBetween

The following code demonstrates the use of different filters with the WFS client.

WFS service explorer

The following code uses the WFS client to explore WFS services. Select a property type layer within the service and see the associated legend.

To access WFS services hosted on non-CORS enabled endpoints, a CORS enabled proxy service can be passed into the proxyService option of the WFS client as shown below.

//Create the WFS client to access the service and use the proxy service settings
client = new{
    url: url,
    proxyService: window.location.origin + '/YourCorsEnabledProxyService.ashx?url='

Next steps

Learn more about the classes and methods used in this article:

See the following articles for more code samples to add to your maps: