WFS-运营

本节提供有关WFS服务器提供的操作类型的详细信息。该列表包括由WFS服务器的不同配置(正式称为一致性类)提供的操作。

WFS操作

Operation

Description

GetCapabilities

检索有关服务的元数据,包括支持的操作和参数,以及可用功能类型的列表。

DescribeFeatureType

返回WFS实例提供或接受的功能类型和功能属性的结构描述。

GetFeature

从通过WFS发布的数据存储中返回要素实例的选择。

ListStoredQueries

返回存储在WFS实例中的查询列表。

DescribeStoredQueries

返回存储在WFS实例中的查询的说明。

GetPropertyValue (可选)

检索一组要素实例的要素特性值或复杂要素特性值的一部分

GetFeatureWithLock (可选)

提供与GetFeature请求类似的功能,但具有锁定特性的附加功能,可能是为了后续更新或更改。

LockFeature (可选)

锁定一组要素实例,以便在锁定到位时,其他操作都不能修改数据。

Transaction (可选)

允许修改或删除要素实例及其属性。

CreateStoredQuery (可选)

创建并存储一个查询,客户机可以在稍后的时间点快速轻松地触发该查询。

DropStoredQuery (可选)

从服务器中删除以前存储的查询。

以下是可以发送到由简单和基本的WFS配置提供的操作的请求的示例。

GetCapabilities

请求

WFS服务器响应 GetCapabilities 请求返回有关服务的元数据,包括支持的操作和参数,以及可用功能类型的列表。

GetCapabilities请求的示例如下:

http://cite.deegree.org/deegree-webservices-3.4-RC3/services/wfs200?
SERVICE=WFS&
REQUEST=GetCapabilities&
VERSION=2.0.0

This is a link to a GetCapabilities request.

有三个参数(和值)被传递到WFS服务器, SERVICE=WFSVERSION=2.0.0REQUEST=GetCapabilities .

  • 这个 SERVICE 参数告诉服务器WFS请求即将到来。

  • 这个 VERSION 参数告诉服务器正在请求哪个版本的服务。

  • 这个 REQUEST 参数告诉服务器请求的操作是 GetCapabilities 操作。

WFS标准要求请求始终包含这三个参数。下表总结了执行请求所需的参数和值。

GetCapabilities操作的参数

Parameter

Required

Description

SERVICE

是的

服务名称。值是 WFS

VERSION

是的

服务版本。价值是 1.0.01.1.02.0.02.0.2

REQUEST

是的

操作名称。值是 GetCapabilities

响应

响应是一个功能XML文档,其中详细描述了WFS服务。它包含三个主要部分:

章节能力文件

Service

包含服务元数据,如服务名称、关键字和操作服务器的组织的联系信息。

FeatureTypeList

列出并描述服务提供的功能类型。

Operations

列出可从服务请求的可用操作。

下面显示了一个来自WFS的GetCapabilities响应示例,为了简洁起见,省略了一些部分。

<WFS_Capabilities version="2.0.0" xmlns="http://www.opengis.net/wfs/2.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:ogc="http://www.opengis.net/ogc" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" 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">
  <ows:ServiceIdentification>
    <ows:Title>WFS 2.0.0 CITE Setup</ows:Title>
    <ows:Abstract></ows:Abstract>
    <ows:ServiceType codeSpace="http://www.opengeospatial.org/">WFS</ows:ServiceType>
    <ows:ServiceTypeVersion>2.0.0</ows:ServiceTypeVersion>
  </ows:ServiceIdentification>
  <ows:OperationsMetadata>
    <ows:Operation name="GetCapabilities">
      <ows:DCP>
        <ows:HTTP>
          <ows:Get xlink:href="http://cite.deegree.org/deegree-webservices-3.4-RC3/services/wfs200?"/>
          <ows:Post xlink:href="http://cite.deegree.org/deegree-webservices-3.4-RC3/services/wfs200"/>
        </ows:HTTP>
      </ows:DCP>
      <ows:Parameter name="AcceptVersions">
        <ows:AllowedValues>
          <ows:Value>2.0.0</ows:Value>
        </ows:AllowedValues>
      </ows:Parameter>
    </ows:Operation>
    <ows:Operation name="GetFeature">
      <ows:DCP>
        <ows:HTTP>
          <ows:Get xlink:href="http://cite.deegree.org/deegree-webservices-3.4-RC3/services/wfs200?"/>
          <ows:Post xlink:href="http://cite.deegree.org/deegree-webservices-3.4-RC3/services/wfs200"/>
        </ows:HTTP>
      </ows:DCP>
    </ows:Operation>
</ows:OperationsMetadata>
  <FeatureTypeList>
    <FeatureType>
      <Name xmlns:gn="urn:x-inspire:specification:gmlas:GeographicalNames:3.0">gn:NamedPlace</Name>
      <Title>gn:NamedPlace</Title>
      <DefaultCRS>urn:ogc:def:crs:EPSG::4326</DefaultCRS>
      <OutputFormats>
        <Format>application/xml; subtype="gml/3.2.1"</Format>
      </OutputFormats>
      <ows:WGS84BoundingBox>
        <ows:LowerCorner>-180.000000 -90.000000</ows:LowerCorner>
        <ows:UpperCorner>180.000000 90.000000</ows:UpperCorner>
      </ows:WGS84BoundingBox>
    </FeatureType>
    <FeatureType>
      <Name xmlns:ps="urn:x-inspire:specification:gmlas:ProtectedSites:3.0">ps:ProtectedSite</Name>
      <Title>ps:ProtectedSite</Title>
      <DefaultCRS>urn:ogc:def:crs:EPSG::4326</DefaultCRS>
      <OutputFormats>
        <Format>application/xml; subtype="gml/3.2.1"</Format>
      </OutputFormats>
      <ows:WGS84BoundingBox>
        <ows:LowerCorner>4.486395 51.604992</ows:LowerCorner>
        <ows:UpperCorner>5.928631 51.680515</ows:UpperCorner>
      </ows:WGS84BoundingBox>
    </FeatureType>
  </FeatureTypeList>
  <fes:Spatial_Capabilities>
    <fes:GeometryOperands xmlns:gml="http://www.opengis.net/gml" xmlns:gml32="http://www.opengis.net/gml">
      <fes:GeometryOperand name="gml:Box"/>
      <fes:GeometryOperand name="gml:Envelope"/>
      <fes:GeometryOperand name="gml:Point"/>
      <fes:GeometryOperand name="gml:LineString"/>
      <fes:GeometryOperand name="gml:Curve"/>
      <fes:GeometryOperand name="gml:Polygon"/>
    </fes:GeometryOperands>
    <fes:SpatialOperators>
      <fes:SpatialOperator name="BBOX"/>
      <fes:SpatialOperator name="Intersects"/>
      <fes:SpatialOperator name="Contains"/>
      <fes:SpatialOperator name="Beyond"/>
    </fes:SpatialOperators>
  </fes:Spatial_Capabilities>
</WFS_Capabilities>

GetFeature

WFS服务器响应 GetFeature 请求返回根据请求客户端设置的条件筛选的地理要素实例的集合。

请求可以通过httpget或httppost发送。为了简单起见,下面的示例请求仅通过httpget发送。

请求

最简单的GetFeature请求是下载特性集合而不受任何约束来过滤内容的请求。下面显示了此类请求的一个示例。这个 GetFeature request使用一组描述要返回的地理特征的参数来查询服务器。TYPENAMES参数确定要返回的要素实例集合。

http://cite.deegree.org/deegree-webservices-3.4-RC3/services/wfs200?
SERVICE=WFS&
VERSION=2.0.0&
REQUEST=GetFeature&
TYPENAMES=ps:ProtectedSite

This is a link to an example of a simple GetFeature request.

响应

从上述请求得到的响应摘要如下所示。

<wfs:FeatureCollection
   timeStamp="2017-09-21T18:59:13"
   numberMatched="16"
   numberReturned="16"
   next="https://wfst.axl.aero/AxlRest/wfs?SERVICE=WFS&amp;VERSION=2.0.2&amp;REQUEST=GetFeature&amp;TYPENAMES=ps:ProtectedSite&amp;STARTINDEX=2&amp;COUNT=1"
   xmlns:gts="http://www.isotc211.org/2005/gts"
   xmlns:wfs="http://www.opengis.net/wfs/2.0"
   xmlns:sch="http://purl.oclc.org/dsdl/schematron"
   xmlns:xml="http://www.w3.org/XML/1998/namespace"
   xmlns:base="urn:x-inspire:specification:gmlas:BaseTypes:3.2"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:gco="http://www.isotc211.org/2005/gco"
   xmlns:fes="http://www.opengis.net/fes/2.0"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:ows="http://www.opengis.net/ows/1.1"
   xmlns:gmx="http://www.isotc211.org/2005/gmx"
   xmlns:gss="http://www.isotc211.org/2005/gss"
   xmlns:ps="urn:x-inspire:specification:gmlas:ProtectedSites:3.0"
   xmlns:gsr="http://www.isotc211.org/2005/gsr"
   xmlns:gn="urn:x-inspire:specification:gmlas:GeographicalNames:3.0"
   xmlns:smil20="http://www.w3.org/2001/SMIL20/"
   xmlns:sqm="http://axl.avitech.aero/aviWfsSqm/1.0"
   xmlns:gml="http://www.opengis.net/gml/3.2"
   xmlns:smil20lang="http://www.w3.org/2001/SMIL20/Language"
   xmlns:gmd="http://www.isotc211.org/2005/gmd"
   xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd">
<wfs:member xmlns:wfs="http://www.opengis.net/wfs/2.0">
  <!-- oldId=none ;oldTime=1487178040 ; oldExpiry=0 ;  ; currentTime=1506020133 ; expired=true;-->
  <ps:ProtectedSite xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:ps="urn:x-inspire:specification:gmlas:ProtectedSites:3.0" gml:id="PS_PROTECTEDSITE_16cbb8db-cce1-4e8b-8733-83d53a910ebe">
...
  </ps:ProtectedSite>
</wfs:member></wfs:FeatureCollection>

计数参数

可以添加其他参数以进一步筛选或转换来自WFS的响应。指定参数值所需的信息,包括我们将在下面介绍的其他参数,可从能力文件中获得。

要在上面的GetFeature请求中包含其他参数,只需在URL的末尾添加一个与号(&),然后添加参数名称、等号和要分配给参数的值。例如,下面的GetFeature请求将服务器返回的特性数限制为单个特性实例。限制响应的数量由count参数的值确定。

https://wfst.axl.aero/AxlRest/wfs?
service=WFS&
version=2.0.0&
request=GetFeature&
TypeNames=ps:ProtectedSite&
count=1

This is a link to the request shown above.

请求生成的响应如下所示。请注意,返回的特性实例的数量是1(由根目录中的numberReturned属性显示)wfs:FeatureCollection元素).

<wfs:FeatureCollection
   timeStamp="2017-09-21T18:55:33"
   numberMatched="16"
   numberReturned="1"
   next="https://wfst.axl.aero/AxlRest/wfs?SERVICE=WFS&amp;VERSION=2.0.2&amp;REQUEST=GetFeature&amp;TYPENAMES=ps:ProtectedSite&amp;STARTINDEX=2&amp;COUNT=1"
   xmlns:gts="http://www.isotc211.org/2005/gts"
   xmlns:wfs="http://www.opengis.net/wfs/2.0"
   xmlns:sch="http://purl.oclc.org/dsdl/schematron"
   xmlns:xml="http://www.w3.org/XML/1998/namespace"
   xmlns:base="urn:x-inspire:specification:gmlas:BaseTypes:3.2"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:gco="http://www.isotc211.org/2005/gco"
   xmlns:fes="http://www.opengis.net/fes/2.0"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:ows="http://www.opengis.net/ows/1.1"
   xmlns:gmx="http://www.isotc211.org/2005/gmx"
   xmlns:gss="http://www.isotc211.org/2005/gss"
   xmlns:ps="urn:x-inspire:specification:gmlas:ProtectedSites:3.0"
   xmlns:gsr="http://www.isotc211.org/2005/gsr"
   xmlns:gn="urn:x-inspire:specification:gmlas:GeographicalNames:3.0"
   xmlns:smil20="http://www.w3.org/2001/SMIL20/"
   xmlns:sqm="http://axl.avitech.aero/aviWfsSqm/1.0"
   xmlns:gml="http://www.opengis.net/gml/3.2"
   xmlns:smil20lang="http://www.w3.org/2001/SMIL20/Language"
   xmlns:gmd="http://www.isotc211.org/2005/gmd"
   xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd">
<wfs:member xmlns:wfs="http://www.opengis.net/wfs/2.0">
  <!-- oldId=none ;oldTime=1487178040 ; oldExpiry=0 ;  ; currentTime=1506020133 ; expired=true;-->
  <ps:ProtectedSite xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:ps="urn:x-inspire:specification:gmlas:ProtectedSites:3.0" gml:id="PS_PROTECTEDSITE_16cbb8db-cce1-4e8b-8733-83d53a910ebe">
    <gml:name>ProtectedSite1</gml:name>
    <ps:geometry>
      <gml:MultiSurface gml:id="PS_PROTECTEDSITE_16cbb8db-cce1-4e8b-8733-83d53a910ebe_PS_GEOMETRY" srsName="urn:ogc:def:crs:EPSG::4326">
        <gml:surfaceMember>
          <gml:Polygon gml:id="GEOMETRY_7fd8f3e7-d283-4ce5-9722-e612bf465a3b" srsName="urn:ogc:def:crs:EPSG::4326">
            <gml:exterior>
              <gml:LinearRing>
                <gml:posList>
                                                                          51.628734 5.507951 51.629015 5.508402 51.629694 5.507409 51.628721 5.507150 51.628734
                                                                          5.507951
                                                                  </gml:posList>
              </gml:LinearRing>
            </gml:exterior>
          </gml:Polygon>
        </gml:surfaceMember>
      </gml:MultiSurface>
    </ps:geometry>
    <ps:inspireID>
      <base:Identifier>
        <base:localId>FB8DCB4E-03BB-4E8A-BB9D-04A44295DF58</base:localId>
        <base:namespace>NL.9930.EHS</base:namespace>
      </base:Identifier>
    </ps:inspireID>
    <ps:siteDesignation>
      <ps:DesignationType>
        <ps:designationScheme>ecologischeHoofdstructuur</ps:designationScheme>
        <ps:designation>ecologischeHoofdstructuur</ps:designation>
        <ps:percentageUnderDesignation>100</ps:percentageUnderDesignation>
      </ps:DesignationType>
    </ps:siteDesignation>
  </ps:ProtectedSite>
</wfs:member></wfs:FeatureCollection>

边界框(BBOX)参数

可以添加到GetFeature请求的另一个参数是边界框(BBOX)的参数。此参数是一个逗号分隔的列表,由四个数字组成,表示应返回的要素实例的最小和最大边界坐标。下面显示了使用BBOX参数的示例。

http://cite.deegree.org/deegree-webservices-3.4-RC3/services/wfs200?service=WFS&version=2.0.0&request=GetFeature&TypeNames=ps:ProtectedSite&BBOX=51.607317,5.106151,51.629884,5.228022

This is a link to the request shown above.

上面的请求返回的响应如下所示。为了简洁起见,这里提供了一些缺少的内容。

<wfs:FeatureCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wfs="http://www.opengis.net/wfs/2.0" timeStamp="2017-09-21T18:14:50Z" xmlns:gml="http://www.opengis.net/gml/3.2" numberMatched="1" numberReturned="1">
<wfs:member>
<ps:ProtectedSite xmlns:ps="urn:x-inspire:specification:gmlas:ProtectedSites:3.0" gml:id="PS_PROTECTEDSITE_a367af0b-9457-4445-9cbd-eb48ae7a844a">
...
</ps:ProtectedSite>
</wfs:member>
</wfs:FeatureCollection>

PropetyName参数

可以添加到GetFeature请求的另一个参数是propertyName。此参数返回只包含指定属性的功能实例。在具有多个属性的功能类型通过带宽有限的网络提供服务的情况下,此功能尤其有用。客户机应用程序可以选择要在功能实例中返回的属性。下面显示了使用此参数的示例。

https://services.interactive-instruments.de/ogc-reference/simple/wfs?version=2.0.0&request=getfeature&service=wfs&typenames=ci:City&count=3&propertyName=inhabitants

This is a link to the request shown above.

上面的请求返回的响应如下所示。

<wfs:FeatureCollection timeStamp="2017-09-21T21:17:32.296+02:00" numberReturned="3" numberMatched="unknown" xmlns="http://www.interactive-instruments.de/namespaces/demo/cities/4.1/cities" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:member>
<City gml:id="City.10">
<location>
<gml:Point gml:id="city.id.10.location.Geom_0" srsName="urn:ogc:def:crs:EPSG::25832" srsDimension="2">
<gml:pos>486890.340 5881020.962</gml:pos>
</gml:Point>
</location>
<inhabitants>547300</inhabitants>
</City>
</wfs:member>
<wfs:member>
<City gml:id="City.11">
<location>
<gml:Point gml:id="city.id.11.location.Geom_0" srsName="urn:ogc:def:crs:EPSG::25832" srsDimension="2">
<gml:pos>364883.268 5620035.394</gml:pos>
</gml:Point>
</location>
<inhabitants>324800</inhabitants>
</City>
</wfs:member>
<wfs:member>
<City gml:id="City.9">
<location>
<gml:Point gml:id="city.id.9.location.Geom_0" srsName="urn:ogc:def:crs:EPSG::25832" srsDimension="2">
<gml:pos>361905.275 5702287.179</gml:pos>
</gml:Point>
</location>
<inhabitants>574600</inhabitants>
</City>
</wfs:member>
</wfs:FeatureCollection>

sortBy参数

WFS返回的结果也可以通过sortBy参数按特定的顺序组织。此参数按指定参数确定的序列返回要素实例。在要素类型具有表示数量或总体的特性的情况下,此功能尤其有用。下面显示了使用此参数的示例。

https://services.interactive-instruments.de/ogc-reference/simple/wfs?version=2.0.0&request=getfeature&service=wfs&typenames=ci:City&sortBy=inhabitants&propertyName=inhabitants

The link to the request above is shown below.

由上述请求得到的响应如下所示。为了简洁起见,省略了一些内容。

<?xml version="1.0" encoding="utf-8"?>
<wfs:FeatureCollection timeStamp="2017-09-21T21:17:32.296+02:00" numberReturned="11" numberMatched="unknown" xmlns="http://www.interactive-instruments.de/namespaces/demo/cities/4.1/cities" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:member>
<City gml:id="City.11">
<location>
<gml:Point gml:id="city.id.11.location.Geom_0" srsName="urn:ogc:def:crs:EPSG::25832" srsDimension="2">
<gml:pos>364883.268 5620035.394</gml:pos>
</gml:Point>
</location>
<inhabitants>324800</inhabitants>
</City>
</wfs:member>
<wfs:member>
<City gml:id="City.10">
<location>
<gml:Point gml:id="city.id.10.location.Geom_0" srsName="urn:ogc:def:crs:EPSG::25832" srsDimension="2">
<gml:pos>486890.340 5881020.962</gml:pos>
</gml:Point>
</location>
<inhabitants>547300</inhabitants>
</City>
</wfs:member>
<wfs:member>
<City gml:id="City.9">
<location>
<gml:Point gml:id="city.id.9.location.Geom_0" srsName="urn:ogc:def:crs:EPSG::25832" srsDimension="2">
<gml:pos>361905.275 5702287.179</gml:pos>
</gml:Point>
</location>
<inhabitants>574600</inhabitants>
</City>
</wfs:member>
</wfs:FeatureCollection>

srsName参数

此参数用于指定用于编码要素几何图形的空间参考系。可以从GetCapabilities响应中标识每个要素类型所允许的空间参考系统。

https://services.interactive-instruments.de/ogc-reference/simple/wfs?version=2.0.0&request=getfeature&service=wfs&typenames=ci:City&count=1&srsName=urn:ogc:def:crs:EPSG::4326

The link to the request above is shown below.

由上述请求得到的响应如下所示。为了简洁起见,省略了一些内容。

<wfs:FeatureCollection timeStamp="2017-09-21T21:26:02.213+02:00" numberReturned="1" numberMatched="unknown" xmlns="http://www.interactive-instruments.de/namespaces/demo/cities/4.1/cities" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:boundedBy>
<gml:Envelope srsName="urn:ogc:def:crs:EPSG::4326" srsDimension="2">
<gml:lowerCorner>52.521400003005 13.405700006106</gml:lowerCorner>
<gml:upperCorner>52.521400003005 13.405700006106</gml:upperCorner>
</gml:Envelope>
</wfs:boundedBy>
<wfs:member>
<City gml:id="City.1">
<name>Berlin</name>
<location>
<gml:Point gml:id="city.id.1.location.Geom_0" srsName="urn:ogc:def:crs:EPSG::4326" srsDimension="2">
<gml:pos>52.521400003005 13.405700006106</gml:pos>
</gml:Point>
</location>
<country>Germany</country>
<inhabitants>3460700</inhabitants>
<lzi>2011-03-17T15:32:54Z</lzi>
<function>capital</function>
</City>
</wfs:member>
</wfs:FeatureCollection>

featureId参数

此参数用于筛选请求返回的功能。

http://localhost:8080/geoserver/wfs?
request=GetFeature&
version=2.0.0&
typeName=topp:states&
FEATUREID=states.3

The link to the request above is shown below.

由上述请求得到的响应如下所示。为了简洁起见,省略了一些内容。

<wfs:FeatureCollection xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:topp="http://www.openplans.org/topp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" numberMatched="1" numberReturned="1" timeStamp="2017-09-21T19:38:52.788Z">
<wfs:member>
<topp:states gml:id="states.3">
<topp:the_geom>
<gml:MultiSurface srsName="urn:ogc:def:crs:EPSG::4326" srsDimension="2">
<gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>38.557476 -75.70742 38.649551 -75.71106 38.83017 -75.724937 39.141548 -75.752922 39.247753 -75.761658 38.450451 -75.093094 38.455208 -75.350204 38.463066 -75.69915 38.557476 -75.70742</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember>
</gml:MultiSurface>
</topp:the_geom>
<topp:STATE_NAME>Delaware</topp:STATE_NAME>
<topp:SAMP_POP>102776.0</topp:SAMP_POP>
</topp:states>
</wfs:member>
</wfs:FeatureCollection>

查询操作

到目前为止,我们只展示了通过httpget方法作为url发送的GetFeature请求示例。也可以通过httppost方法将请求主体作为XML文档发送。

下面是一个GetFeature请求的示例,该请求包含一个查询操作,并通过httppost方法发送。

请求被发送到以下URL https://services.interactive-instruments.de/ogc-reference/simple/wfs

<wfs:GetFeature service="WFS" version="2.0.0"
    xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:ci="http://www.interactive-instruments.de/namespaces/demo/cities/4.1/cities" xmlns:fes="http://www.opengis.net/fes/2.0"
    xmlns:sf="http://www.openplans.org/spearfish" 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">
    <wfs:Query typeNames="ci:City">
    <wfs:PropertyName resolve="local">ci:inhabitants</wfs:PropertyName>
        <fes:Filter>
            <fes:PropertyIsLessThan>
               <fes:ValueReference>ci:inhabitants</fes:ValueReference>
               <fes:Literal>400000</fes:Literal>
            </fes:PropertyIsLessThan>
        </fes:Filter>
    </wfs:Query>
</wfs:GetFeature>

上面的请求返回的响应如下所示。

<wfs:FeatureCollection timeStamp="2017-09-22T09:56:55.908+02:00" numberReturned="1" numberMatched="unknown" xmlns="http://www.interactive-instruments.de/namespaces/demo/cities/4.1/cities" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.interactive-instruments.de/namespaces/demo/cities/4.1/cities https://services.interactive-instruments.de/ogc-reference/schema/demo/cities/4.1/Cities.xsd http://www.opengis.net/wfs/2.0 https://services.interactive-instruments.de/ogc-reference/schema/ogc/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 https://services.interactive-instruments.de/ogc-reference/schema/ogc/gml/3.2.1/gml.xsd http://www.opengis.net/gml/3.2 https://services.interactive-instruments.de/ogc-reference/schema/ogc/gml/3.2.1/gml.xsd">
<wfs:boundedBy>
<gml:Envelope srsName="urn:ogc:def:crs:EPSG::25832" srsDimension="2">
<gml:lowerCorner>364883.268 5620035.394</gml:lowerCorner>
<gml:upperCorner>364883.268 5620035.394</gml:upperCorner>
</gml:Envelope>
</wfs:boundedBy>
<wfs:member>
<City gml:id="City.11">
<name>Bonn</name>
<location>
<gml:Point gml:id="city.id.11.location.Geom_0" srsName="urn:ogc:def:crs:EPSG::25832" srsDimension="2">
<gml:pos>364883.268 5620035.394</gml:pos>
</gml:Point>
</location>
<country>Germany</country>
<inhabitants>324800</inhabitants>
</City>
</wfs:member>
</wfs:FeatureCollection>

GetPropertyValue

返回请求中指定的功能属性的值。当通过带宽有限的网络访问服务器时,此操作非常有用,因为它只返回属性值,而不是完整的功能实例数据。

请求

下面是一个包含查询操作并通过httppost方法发送的GetPropertyValue请求的示例。

请求被发送到以下URL https://services.interactive-instruments.de/ogc-reference/simple/wfs

<wfs:GetPropertyValue service="WFS" version="2.0.0"
   valueReference="ci:inhabitants"
   resolve="local"
   resolveDepth="*"
    xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:ci="http://www.interactive-instruments.de/namespaces/demo/cities/4.1/cities" xmlns:fes="http://www.opengis.net/fes/2.0"
    xmlns:sf="http://www.openplans.org/spearfish" 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">
    <wfs:Query typeNames="ci:City">
        <fes:Filter>
            <fes:PropertyIsLessThan>
               <fes:ValueReference>ci:inhabitants</fes:ValueReference>
               <fes:Literal>400000</fes:Literal>
            </fes:PropertyIsLessThan>
        </fes:Filter>
    </wfs:Query>
</wfs:GetPropertyValue>

响应

由上述请求得到的响应如下所示。

<wfs:ValueCollection timeStamp="2017-09-22T10:06:30.991+02:00" numberReturned="1" numberMatched="unknown" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:member>324800</wfs:member>
</wfs:ValueCollection>

DescribeFeatureType

返回请求中指定的功能类型的结构说明,包括属性。

请求

DescribeFeatureType请求的示例如下:

https://services.interactive-instruments.de/ogc-reference/simple/wfs?
version=2.0.0&
request=describeFeatureType&
service=wfs&
typenames=ci:City

This is a link to the request presented above.

响应

响应是一个XML架构定义文档,其中包含指定功能类型的详细描述。注意,在某些情况下,XML模式定义文档可能会导入外部托管的定义。

<schema targetNamespace="http://www.interactive-instruments.de/namespaces/demo/cities/4.1/cities" xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:ci="http://www.interactive-instruments.de/namespaces/demo/cities/4.1/cities" xmlns:gml="http://www.opengis.net/gml/3.2">
<import namespace="http://www.opengis.net/gml/3.2" schemaLocation="https://services.interactive-instruments.de/ogc-reference/schema/ogc/gml/3.2.1/gml.xsd"/>
<element name="City" substitutionGroup="ci:NamedGeoObject" type="ci:CityType"/>
<element abstract="true" name="NamedGeoObject" substitutionGroup="gml:AbstractFeature" type="ci:NamedGeoObjectType"/>
<complexType name="CityType">
<complexContent>
<extension base="ci:NamedGeoObjectType">
<sequence>
<element name="location" type="gml:PointPropertyType"/>
<element maxOccurs="unbounded" minOccurs="0" name="alternativeName" type="ci:AlternativeNamePropertyType"/>
<element name="country" type="string"/>
<element name="inhabitants" type="integer"/>
<element name="lzi" type="dateTime"/>
<element name="function" nillable="true" type="string"/>
<element maxOccurs="unbounded" minOccurs="0" name="district" type="gml:ReferenceType"/>
<element maxOccurs="unbounded" minOccurs="0" name="passingRiver" type="gml:ReferenceType"/>
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="NamedGeoObjectType">
<complexContent>
<extension base="gml:AbstractFeatureType">
<sequence>
<element minOccurs="0" name="name" type="string"/>
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="AlternativeNamePropertyType">
<sequence>
<element ref="ci:AlternativeName"/>
</sequence>
</complexType>
<element name="AlternativeName" substitutionGroup="gml:AbstractObject" type="ci:AlternativeNameType"/>
<complexType name="AlternativeNameType">
<sequence>
<element name="name" type="string"/>
<element name="language" type="string"/>
</sequence>
</complexType>
</schema>

存储的查询

通过一个简短的单行URL,存储查询允许客户端应用程序调用最初可能是由多行XML组成的查询。

存储的查询表达式可用于GetPropertyValue、GetFeature、GetFeatureWithLock或LockFeature操作中。参数可以传递给所请求的操作对其进行操作的存储查询。

所有服务器应实现列出、描述和执行基于其标识符获取特征的存储查询的能力。还可以提供其他存储查询。

ListStoredQueries

返回存储在服务器内部的查询列表。

请求

ListStoredQueries请求的示例如下:

http://localhost:8080/geoserver/wfs?
request=ListStoredQueries&
version=2.0.0

This is a link to the request presented above.

响应

响应是一个XML文档,它显示服务器中存储的每个查询的标识符和名称。例如,在GetFeature请求中通过STOREDQUERY_ID参数调用存储的查询时使用标识符。

<wfs:ListStoredQueriesResponse xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:StoredQuery id="urn:ogc:def:query:OGC-WFS::GetFeatureById">
<wfs:Title xml:lang="en">Get feature by identifier</wfs:Title>
<wfs:ReturnFeatureType/>
</wfs:StoredQuery>
</wfs:ListStoredQueriesResponse>

DescribeStoredQueries

返回请求参数中引用的存储查询的说明。

请求

DescribeStoredQueries请求的示例如下:

http://localhost:8080/geoserver/wfs?
request=DescribeStoredQueries&
STOREDQUERY_ID=urn:ogc:def:query:OGC-WFS::GetFeatureById&
version=2.0.0

This is a link to the request presented above.

响应

响应是一个XML文档,它描述由STOREDQUERY_ID参数指定的标识符指定的存储查询。

<wfs:DescribeStoredQueriesResponse xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:StoredQueryDescription id="urn:ogc:def:query:OGC-WFS::GetFeatureById">
<wfs:Title xml:lang="en">Get feature by identifier</wfs:Title>
<wfs:Parameter name="ID" type="xs:string"/>
<wfs:QueryExpressionText isPrivate="true" language="urn:ogc:def:queryLanguage:OGC-WFS::WFS_QueryExpression" returnFeatureTypes=""/>
</wfs:StoredQueryDescription>
</wfs:DescribeStoredQueriesResponse>

交易

此可选操作允许更新或删除要素实例及其属性。该操作还可用于插入新功能。WFS标准不强制实施任何特定的安全模型,因此实现应该实现适合于其自身基础设施的安全模型。

请求

下面显示了一个请求示例。由于请求修改数据,我们建议安装一个WFS的本地实例。下面的示例针对本地托管的WFS实例进行了测试<本地主机http://localhost:8080/geoserver/wfs>

<wfs:Transaction version="2.0.0" service="WFS"
 xmlns="http://www.someserver.com/myns"
 xmlns:fes="http://www.opengis.net/fes/2.0"
 xmlns:topp="http://www.openplans.org/topp"
 xmlns:wfs="http://www.opengis.net/wfs/2.0"
 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.0/wfs.xsd">
 <wfs:Update typeName="topp:tasmania_roads">
 <wfs:Property>
 <wfs:ValueReference>TYPE</wfs:ValueReference>
 <wfs:Value>road</wfs:Value>
 </wfs:Property>
 <fes:Filter>
 <fes:ResourceId rid="tasmania_roads.1"/>
 </fes:Filter>
 </wfs:Update>
</wfs:Transaction>

响应

响应是一个XML文档,用于确认事务是否成功。

<wfs:TransactionResponse xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.0" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd">
<wfs:TransactionSummary>
<wfs:totalInserted>0</wfs:totalInserted>
<wfs:totalUpdated>1</wfs:totalUpdated>
<wfs:totalReplaced>0</wfs:totalReplaced>
<wfs:totalDeleted>0</wfs:totalDeleted>
</wfs:TransactionSummary>
<wfs:UpdateResults><wfs:Feature>
<fes:ResourceId rid="tasmania_roads.1"/>
</wfs:Feature>
</wfs:UpdateResults>
</wfs:TransactionResponse>

GetFeatureWithLock

提供与GetFeature请求类似的功能,但具有锁定特性的附加功能,可能是为了后续更新或更改。

请求

下面显示了一个请求示例。由于请求修改数据源的状态,我们建议使用WFS的本地实例。下面的示例针对本地托管的WFS实例进行了测试<http://localhost:8080/geoserver/wfs>

<wfs:GetFeatureWithLock service="WFS" version="2.0.0"
 handle="GetFeatureWithLock-tc1" expiry="5" resultType="results"
 xmlns:topp="http://www.openplans.org/topp"
 xmlns:fes="http://www.opengis.net/fes/2.0"
 xmlns:wfs="http://www.opengis.net/wfs/2.0"
 valueReference="the_geom"  count="1">
  <wfs:Query typeNames="topp:states"/>
</wfs:GetFeatureWithLock>

响应

响应是一个特性集合,类似于从GetFeature响应接收的特性集合。为了简洁起见,下面的例子被缩短了。

<wfs:FeatureCollection xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:topp="http://www.openplans.org/topp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" lockId="GetFeatureWithLock-tc1_6badb1c771c6ee70" numberMatched="49" numberReturned="1" timeStamp="2017-09-29T07:25:43.601Z" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd http://www.openplans.org/topp http://localhost:8080/geoserver/wfs?service=WFS&amp;version=2.0.0&amp;request=DescribeFeatureType&amp;typeName=topp%3Astates http://www.opengis.net/gml/3.2 http://localhost:8080/geoserver/schemas/gml/3.2.1/gml.xsd">
<wfs:member>
<topp:states gml:id="states.1">
<topp:the_geom>
<gml:MultiSurface srsName="urn:ogc:def:crs:EPSG::4326" srsDimension="2"><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>37.51099 -88.071564 37.476273 -88.087883 37.628479 -88.157631 37.583572 -88.134171 37.51099 -88.071564</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember></gml:MultiSurface>
</topp:the_geom>
<topp:STATE_NAME>Illinois</topp:STATE_NAME>
<topp:STATE_FIPS>17</topp:STATE_FIPS>
<topp:SAMP_POP>1747776.0</topp:SAMP_POP>
</topp:states>
</wfs:member>
</wfs:FeatureCollection>

LockFeature

锁定一组要素实例,以便在锁定到位时,其他操作都不能修改数据。

请求

下面显示了一个请求示例。由于请求修改数据源的状态,我们建议使用WFS的本地实例。下面的示例针对本地托管的WFS实例进行了测试<http://localhost:8080/geoserver/wfs>

<wfs:LockFeature
   service="WFS"
   version="2.0.0"
   expiry="5"
   xmlns:topp="http://www.openplans.org/topp"
   xmlns:wfs="http://www.opengis.net/wfs/2.0"
   xmlns:ogc="http://www.opengis.net/ogc"
   xmlns:fes="http://www.opengis.net/fes/2.0"
   xmlns:gml="http://www.opengis.net/gml"
   xmlns:myns="http://www.example.com/myns"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
   <wfs:Query typeNames="topp:states">
        <fes:Filter>
            <fes:PropertyIsEqualTo>
               <fes:ValueReference>topp:STATE_NAME</fes:ValueReference>
               <fes:Literal>Illinois</fes:Literal>
            </fes:PropertyIsEqualTo>
        </fes:Filter>
   </wfs:Query>
</wfs:LockFeature>

响应

响应是一个特性集合,类似于从GetFeature响应接收的特性集合。为了简洁起见,下面的例子被缩短了。

<wfs:LockFeatureResponse xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" lockId="GeoServer_5dcc3c771e1b15c" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd">
    <wfs:FeaturesLocked><fes:ResourceId rid="states.1"/></wfs:FeaturesLocked>
</wfs:LockFeatureResponse>

CreateStoredQuery

创建并存储一个查询,客户机可以在稍后的时间点快速轻松地触发该查询。

请求

下面显示了一个请求示例。由于请求持久化了一个查询,我们建议使用WFS的本地实例。下面的示例针对本地托管的WFS实例进行了测试<http://localhost:8080/geoserver/wfs>

<wfs:CreateStoredQuery service='WFS' version='2.0.0'
 xmlns:wfs='http://www.opengis.net/wfs/2.0'
 xmlns:fes='http://www.opengis.org/fes/2.0'
 xmlns:gml='http://www.opengis.net/gml/3.2'
 xmlns:myns='http://www.someserver.com/myns'
 xmlns:xsd='http://www.w3.org/2001/XMLSchema'
 xmlns:topp='http://www.openplans.org/topp'>
  <wfs:StoredQueryDefinition id='stateStoredQuery'>
    <wfs:Parameter name='stateName' type='xsd:String'/>
    <wfs:QueryExpressionText
     returnFeatureTypes='topp:states'
     language='urn:ogc:def:queryLanguage:OGC-WFS::WFS_QueryExpression'
     isPrivate='false'>
      <wfs:Query typeNames='topp:states'>
        <fes:Filter>
            <fes:PropertyIsEqualTo>
               <fes:ValueReference>topp:STATE_NAME</fes:ValueReference>
               <fes:Literal>${stateName}</fes:Literal>
            </fes:PropertyIsEqualTo>
        </fes:Filter>
      </wfs:Query>
    </wfs:QueryExpressionText>
  </wfs:StoredQueryDefinition>
</wfs:CreateStoredQuery>

响应

下面显示了一个示例响应。

<wfs:CreateStoredQueryResponse xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" status="OK" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd"/>

DropStoredQuery

从服务器中删除以前存储的查询。

请求

下面显示了一个请求示例。由于请求删除了以前存储的查询,我们建议安装一个WFS的本地实例。下面的示例针对本地托管的WFS实例进行了测试<http://localhost:8080/geoserver/wfs>

<wfs:DropStoredQuery
 xmlns:wfs='http://www.opengis.net/wfs/2.0'
 service='WFS' id='myStoredQuery'/>

响应

示例响应如下所示:

<wfs:DropStoredQueryResponse xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" status="OK" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd"/>

例外情况

当客户机向WFS服务器发出的请求未正确执行时,服务器需要报告异常。如果发生异常,服务器将返回包含异常详细信息的报告。

以下异常报告是向服务器发送不支持的功能类型请求时返回的内容的示例。

<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd" version="2.0.0">
<ows:Exception exceptionCode="InvalidParameterValue" locator="typeName">
<ows:ExceptionText>Feature type with name 'AllProtectedSite' is not served by this WFS.</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>