5

How to obtain information about the feature WFS layer in different versions of WFS 1.0.0 / 1.1.0 / 2.0.0 ?

The OL documentation says

Feature format for reading and writing data in the WFS format. By default, supports WFS version 1.1.0. You can pass a GML format as option if you want to read a WFS that contains GML2 (WFS 1.0.0). Also see ol.format.GMLBase which is used by this format.

Ok, example WFS - GetFeature is performed in the version 1.1.0

var f = ol.format.ogc.filter;
var wfs = new ol.format.WFS();
wfs.writeGetFeature({
    srsName: 'EPSG:3857',
    featureNS: 'http://openstreemap.org',
    featurePrefix: 'osm',
    featureTypes: ['water_areas'],
    outputFormat: 'application/json',
    filter: f.and(
        f.like('name', 'Mississippi*'),
        f.equalTo('waterway', 'riverbank')
    )
}); 

But it always forms a request in WFS version 1.1.0.
How to form GetFeature request in WFS versions 2.0.0 using writeGetFeature function?

2

2 Answers 2

2

I may be a bit late, but as I myself was looking for how to change the version in writeGetFeature to 2.0.0 in the current version of OL (v7.2.2) maybe someone else will find this answer useful.
It turns out that specifying the version in the WFS constructor allows writeGetFeature to be written in the desired form:

import { WFS } from 'ol/format.js';
import {
    and as andFilter,
    like as likeFilter,
    equalTo as equalToFilter,
} from 'ol/format/filter.js';

const featureRequest = new WFS({ version: '2.0.0' })
    .writeGetFeature({
        srsName: 'EPSG:3857',
        featureNS: 'http://openstreemap.org',
        featurePrefix: 'osm',
        featureTypes: [ 'water_areas' ],
        outputFormat: 'application/json',
        filter: andFilter(
            likeFilter('name', 'Mississippi*'),
            equalToFilter('waterway', 'riverbank'),
        ),
    });

console.log(new XMLSerializer().serializeToString(featureRequest));

results with:

<GetFeature
    service="WFS" version="2.0.0" outputFormat="application/json"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd"
    xmlns="http://www.opengis.net/wfs/2.0">
  <Query typeNames="osm:water_areas" srsName="EPSG:3857" xmlns:osm="http://openstreemap.org">
    <Filter xmlns="http://www.opengis.net/fes/2.0">
      <And>
        <PropertyIsLike wildCard="*" singleChar="." escapeChar="!">
          <ValueReference>name</ValueReference>
          <Literal>Mississippi*</Literal>
        </PropertyIsLike>
        <PropertyIsEqualTo>
          <ValueReference>waterway</ValueReference>
          <Literal>riverbank</Literal>
        </PropertyIsEqualTo>
      </And>
    </Filter>
  </Query>
</GetFeature>
1

A question on the OL3 developers forum, from June 2014, tells us that whilst there is support for WFS 2 in OL 2, there is no such support for WFS 2 in OL3!

WFS / GML versioning support

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.