3.3. Web Feature Service (WFS)

The 1.0.0 and 1.1.0 WFS standards implemented in QGIS Server provide a HTTP interface to query geographic features from a QGIS project. A typical WFS request defines the QGIS project to use and the layer to query.

Specifications document according to the version number of the service:

Standard requests provided by QGIS Server:

Request

説明

GetCapabilities

Returns XML metadata with information about the server

GetFeature

Returns a selection of features

DescribeFeatureType

Returns a description of feature types and properties

Transaction

Allows features to be inserted, updated or deleted

3.3.1. GetCapabilities

Standard parameters for the GetCapabilities request according to the OGC WFS 1.0.0 and 1.1.0 specifications:

パラメーター

必須

説明

SERVICE

はい

Name of the service (WFS)

REQUEST

はい

Name of the request (GetCapabilities)

VERSION

いいえ

Version of the service

標準のものに加えて、QGISサーバーでは以下の追加パラメータをサポートしています:

パラメーター

必須

説明

MAP

はい

QGIS project file

VERSION

This parameter allows to specify the version of the service to use. Available values for the VERSION parameter are:

  • 1.0.0

  • 1.1.0

If no version is indicated in the request, then 1.1.0 is used by default.

URL example:

http://localhost/qgisserver?
SERVICE=WFS
&VERSION=1.1.0
&...

3.3.2. GetFeature

Standard parameters for the GetFeature request according to the OGC WFS 1.0.0 and 1.1.0 specifications:

パラメーター

必須

説明

SERVICE

はい

Name of the service (WFS)

REQUEST

はい

Name of the request (GetFeature)

VERSION

いいえ

Version of the service

TYPENAME

いいえ

レイヤの名前

FEATUREID

いいえ

Filter the features by ids

OUTPUTFORMAT

いいえ

Output Format

RESULTTYPE

いいえ

Type of the result

PROPERTYNAME

いいえ

Name of properties to return

MAXFEATURES

いいえ

Maximum number of features to return

SRSNAME

いいえ

座標参照系

FILTER

いいえ

OGC Filter Encoding

BBOX

いいえ

Map Extent

SORTBY

いいえ

Sort the results

標準のものに加えて、QGISサーバーでは以下の追加パラメータをサポートしています:

パラメーター

必須

説明

MAP

はい

QGIS project file

STARTINDEX

いいえ

Paging

GEOMETRYNAME

いいえ

Type of geometry to return

EXP_FILTER

いいえ

Expression filtering

TYPENAME

This parameter allows to specify layer names and is mandatory if FEATUREID is not set.

URL example:

http://localhost/qgisserver?
SERVICE=WFS
&VERSION=1.1.0
&REQUEST=GetFeature
&TYPENAME=countries

FEATUREID

This parameter allows to specify the ID of a specific feature and is formed like typename.fid,typename.fid,....

URL example:

http://localhost/qgisserver?
SERVICE=WFS
&REQUEST=GetFeature
&FEATUREID=countries.0,places.1

XML response:

<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd http://www.qgis.org/gml http://192.168.1.15/qgisserver?SERVICE=WFS&VERSION=1.1.0&REQUEST=DescribeFeatureType&TYPENAME=countries,places&OUTPUTFORMAT=text/xml; subtype%3Dgml/3.1.1">
  <gml:boundedBy>
    ...
  </gml:boundedBy>
  <gml:featureMember>
    <qgs:countries gml:id="countries.1">
      ...
    </qgs:countries>
  </gml:featureMember>
  <gml:featureMember>
    <qgs:places gml:id="places.1">
      ...
    </qgs:places>
  </gml:featureMember>
</wfs:FeatureCollection>

OUTPUTFORMAT

This parameter may be used to specify the format of the response. If VERSION is greater or equal than 1.1.0, GML3 is the default format. Otherwise GML2 is used.

Available values are:

  • gml2

  • text/xml; subtype=gml/2.1.2

  • gml3

  • text/xml; subtype=gml/3.1.1

  • geojson

  • application/vnd.geo+json,

  • application/vnd.geo json

  • application/geo+json

  • application/geo json

  • application/json

URL example:

http://localhost/qgisserver?
SERVICE=WFS
&REQUEST=GetFeature
&FEATUREID=countries.0
&OUTPUTFORMAT=geojson

GeoJSON response:

{
    "type":"FeatureCollection",
    "bbox":[
        -180,
        -90,
        180,
        83.6236
    ],
    "features":[
        {
            "bbox":[
                -61.891113,
                16.989719,
                -61.666389,
                17.724998
            ],
            "geometry":{
                "coordinates":[
                    "..."
                ],
                "type":"MultiPolygon"
            },
            "id":"countries.1",
            "properties":{
                "id":1,
                "name":"Antigua and Barbuda"
            },
            "type":"Feature"
        }
    ]
}

RESULTTYPE

This parameter may be used to specify the kind of result to return. Available values are:

  • results: the default behavior

  • hits: returns only a feature count

URL example:

http://localhost/qgisserver?
SERVICE=WFS
&VERSION=1.1.0
&REQUEST=GetFeature
&RESULTTYPE=hits
&...

PROPERTYNAME

This parameter may be used to specify a specific property to return. A property needs to be mapped with a TYPENAME or a FEATUREID:

Valid URL example:

http://localhost/qgisserver?
SERVICE=WFS
&REQUEST=GetFeature
&PROPERTYNAME=name
&TYPENAME=places

On the contrary, the next URL will return an exception:

http://localhost/qgisserver?
SERVICE=WFS
&REQUEST=GetFeature
&PROPERTYNAME=name
&TYPENAME=places,countries
<ServiceExceptionReport xmlns="http://www.opengis.net/ogc" version="1.2.0">
    <ServiceException code="RequestNotWellFormed">There has to be a 1:1 mapping between each element in a TYPENAME and the PROPERTYNAME list</ServiceException>
</ServiceExceptionReport>

MAXFEATURES

This parameter allows to limit the number of features returned by the request.

注釈

This parameter may be useful to improve performances when underlying vector layers are heavy.

SRSNAME

This parameter allows to indicate the response output Spatial Reference System as well as the BBOX CRS and has to be formed like EPSG:XXXX.

http://localhost/qgisserver?
SERVICE=WFS
&REQUEST=GetFeature
&TYPENAME=places
&SRSNAME=EPSG:32620

FILTER

This parameter allows to filter the response with the Filter Encoding language defined by the OGC Filter Encoding standard.

URL example:

http://localhost/qgisserver?
SERVICE=WFS&
REQUEST=GetFeature&
TYPENAME=places&
FILTER=<Filter><PropertyIsEqualTo><PropertyName>name</PropertyName><Literal>Paris</Literal></PropertyIsEqualTo></Filter>

BBOX

This parameter allows to specify the map extent with units according to the current CRS. Coordinates have to be separated by a comma.

The SRSNAME parameter may specify the CRS of the extent. If not specified, the CRS of the layer is used.

URL example:

http://localhost/qgisserver?
SERVICE=WFS
&REQUEST=GetFeature
&TYPENAME=places
&BBOX=-11.84,42.53,8.46,50.98

The FEATUREID parameter cannot be used with the BBOX. Any attempt will result in an exception:

<ServiceExceptionReport xmlns="http://www.opengis.net/ogc" version="1.2.0">
  <ServiceException code="RequestNotWellFormed">FEATUREID FILTER and BBOX parameters are mutually exclusive</ServiceException>
</ServiceExceptionReport>

SORTBY

This parameter allows to sort resulting features according to property values and has to be formed like propertyname SORTRULE.

Available values for SORTRULE in case of descending sorting:

  • D

  • +D

  • DESC

  • +DESC

Available values for SORTRULE in case of ascending sorting:

  • A

  • +A

  • ASC

  • +ASC

URL example:

http://localhost/qgisserver?
SERVICE=WFS
&REQUEST=GetFeature
&TYPENAME=places
&PROPERTYNAME=name
&MAXFEATURES=3
&SORTBY=name DESC

The corresponding result:

<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd http://www.qgis.org/gml http://192.168.1.15/qgisserver?SERVICE=WFS&VERSION=1.1.0&REQUEST=DescribeFeatureType&TYPENAME=places&OUTPUTFORMAT=text/xml; subtype%3Dgml/3.1.1">
    <gml:boundedBy>
        ...
    </gml:boundedBy>
    <gml:featureMember>
        <qgs:places gml:id="places.90">
            <qgs:name>Zagreb</qgs:name>
        </qgs:places>
    </gml:featureMember>
    <gml:featureMember>
        <qgs:places gml:id="places.113">
            <qgs:name>Yerevan</qgs:name>
        </qgs:places>
    </gml:featureMember>
    <gml:featureMember>
        <qgs:places gml:id="places.111">
            <qgs:name>Yaounde</qgs:name>
        </qgs:places>
    </gml:featureMember>
</wfs:FeatureCollection>

GEOMETRYNAME

このパラメータは、地物に返すジオメトリの種類を指定するために使用できます。利用可能な値は以下のとおりです:

  • 範囲

  • 重心

  • none

URL example:

http://localhost/qgisserver?
SERVICE=WFS
&VERSION=1.1.0
&REQUEST=GetFeature
&GEOMETRYNAME=centroid
&...

STARTINDEX

This parameter is standard in WFS 2.0, but it's an extension for WFS 1.0.0.

Actually, it can be used to skip some features in the result set and in combination with MAXFEATURES, it provides the ability to page through results.

URL example:

http://localhost/qgisserver?
SERVICE=WFS
&VERSION=1.1.0
&REQUEST=GetFeature
&STARTINDEX=2
&...

EXP_FILTER

This parameter allows to filter the response with QGIS expressions.

URL example:

http://localhost/qgisserver?
SERVICE=WFS&
REQUEST=GetFeature&
TYPENAME=places&
EXP_FILTER="name"='Paris'

3.3.3. DescribeFeatureType

Standard parameters for the DescribeFeatureType request according to the OGC WFS 1.0.0 and 1.1.0 specifications:

パラメーター

必須

説明

SERVICE

はい

Name of the service (WFS)

REQUEST

はい

Name of the request (DescribeFeatureType)

VERSION

いいえ

Version of the service

OUTPUTFORMAT

いいえ

Format of the response

TYPENAME

いいえ

レイヤの名前

標準のものに加えて、QGISサーバーでは以下の追加パラメータをサポートしています:

パラメーター

必須

説明

MAP

はい

QGIS project file

URL example:

http://localhost/qgisserver?
SERVICE=WFS
&VERSION=1.1.0
&REQUEST=DescribeFeatureType
&TYPENAME=countries

Output response:

<schema xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:qgs="http://www.qgis.org/gml" xmlns:gml="http://www.opengis.net/gml" targetNamespace="http://www.qgis.org/gml" version="1.0" elementFormDefault="qualified">
  <import schemaLocation="http://schemas.opengis.net/gml/3.1.1/base/gml.xsd" namespace="http://www.opengis.net/gml"/>
  <element type="qgs:countriesType" substitutionGroup="gml:_Feature" name="countries"/>
  <complexType name="countriesType">
    <complexContent>
      <extension base="gml:AbstractFeatureType">
        <sequence>
          <element minOccurs="0" type="gml:MultiPolygonPropertyType" maxOccurs="1" name="geometry"/>
          <element type="long" name="id"/>
          <element nillable="true" type="string" name="name"/>
        </sequence>
      </extension>
    </complexContent>
  </complexType>
</schema>

3.3.4. Transaction

This request allows to update, delete or add one or several features thanks to a XML document. The delete action may be achieved with a POST request as well as with the OPERATION parameter while the add and the update operations may be achieved through POST request only.

Standard parameters for the Transaction request according to the OGC WFS 1.0.0 and 1.1.0 specifications:

パラメーター

必須

説明

SERVICE

はい

Name of the service (WFS)

REQUEST

はい

Name of the request (Transaction)

VERSION

いいえ

Version of the service

FILTER

いいえ

OGC Filter Encoding

BBOX

いいえ

Map Extent

FEATUREID

いいえ

Filter the features by ids

TYPENAME

いいえ

レイヤの名前

標準のものに加えて、QGISサーバーでは以下の追加パラメータをサポートしています:

パラメーター

必須

説明

MAP

はい

QGIS project file

OPERATION

いいえ

Specify the operation

EXP_FILTER

いいえ

Expression filtering

OPERATION

This parameter allows to delete a feature without using a POST request with a dedicated XML document.

URL example:

http://localhost/qgisserver?
SERVICE=WFS
&VERSION=1.1.0
&REQUEST=Transaction
&OPERATION=DELETE
&FEATUREID=24

注釈

FEATUREID, BBOX and FILTER parameters are mutually exclusive and prioritized in this order.

Add features

POST request example:

wget --post-file=add.xml "http://localhost/qgisserver?SERVICE=WFS&REQUEST=Transaction"

with the add.xml document:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:Transaction service="WFS" version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ogc="http://www.opengis.net/ogc" xmlns="http://www.opengis.net/wfs" updateSequence="0" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd" xmlns:gml="http://www.opengis.net/gml"  xmlns:ows="http://www.opengis.net/ows">
  <wfs:Insert idgen="GenerateNew">
    <qgs:places>
      <qgs:geometry>
        <gml:Point srsDimension="2" srsName="http://www.opengis.net/def/crs/EPSG/0/4326">
          <gml:coordinates decimal="." cs="," ts=" ">-4.6167,48.3833</gml:coordinates>
        </gml:Point>
      </qgs:geometry>
      <qgs:name>Locmaria-Plouzané</qgs:name>
    </qgs:places>
  </wfs:Insert>
</wfs:Transaction>

Update features

POST request example:

wget --post-file=update.xml "http://localhost/qgisserver?SERVICE=WFS&REQUEST=Transaction"

with the update.xml document:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:Transaction service="WFS" version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ogc="http://www.opengis.net/ogc" xmlns="http://www.opengis.net/wfs" updateSequence="0" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd" xmlns:gml="http://www.opengis.net/gml"  xmlns:ows="http://www.opengis.net/ows">
    <wfs:Update typeName="places">
      <wfs:Property>
          <wfs:Name>name</wfs:Name>
          <wfs:Value>Lutece</wfs:Value>
      </wfs:Property>
      <ogc:Filter>
          <ogc:FeatureId fid="24"/>
      </ogc:Filter>
    </wfs:Update>
</wfs:Transaction>

Delete features

POST request example:

wget --post-file=delete.xml "http://localhost/qgisserver?SERVICE=WFS&REQUEST=Transaction"

with the delete.xml document:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:Transaction service="WFS" version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ogc="http://www.opengis.net/ogc" xmlns="http://www.opengis.net/wfs" updateSequence="0" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd" xmlns:gml="http://www.opengis.net/gml"  xmlns:ows="http://www.opengis.net/ows">
    <wfs:Delete typeName="places">
        <ogc:Filter>
            <ogc:FeatureId fid="24"/>
        </ogc:Filter>
    </wfs:Delete>
</wfs:Transaction>