.. _chapter-wfs:
WFS-要素 Web 服务
=============================
概述
------
WFS(OpenGIS® Web Feature Service)当前版本是 1.1.0。
WFS 标准定义了一些操作,这些操作允许用户在分布式的环境下通过 HTTP对空间数据进行查询、编辑等操作。
WFS 服务要求服务的接口必须由 XML 描述,另外数据交互必须由 GML 进行,数据过滤采用CQl [18]_ 语言。
种类与操作
----------------------
当一个客户端想要访问 WFS 服务时,一般会涉及到以下的流程:
1. 通过操作获取 WFS 服务支持的操作和要素类(Feature Type,可以理解为 WFS 中的数据集)。
2. (可能)通过操作获取 WFS 服务支持的要素类的定义。
3. 客户端发送某个操作的请求。
4. WFS 服务处理请求。
5. WFS 服务返回处理的结果和状态。
上面几个步骤中所提到的“操作”包括:
1. GetCapabilities(获取服务中的要素类及支持的操作)
2. DescribeFeatureType(描述要素类的信息)
3. GetFeature(获取要素)
4. GetGmlObject(通过 XLink 获取 GML 对象)
5. Transaction(创建、更新、删除数据的事务操作)
6. LockFeature(在事务过程中锁定要素)
但是,这些操作并不是必须全部实现,而是实现全部或部分。根据所支持的操作不同,WFS 可以分为 3 类:
1. Basic WFS(就是最常被提及的 WFS,必须支持 GetCapabilities/
DescribeFeatureType GetFeature 操作,在功能上意味着提供一个叧读的数据服务)
2. XLink WFS(必须在 Basic WFS 基础上加上 GetGmlObject 操作)
3. Transaction WFS(也有称为 WFS-T,必须在 Basic WFS 基础上加上
Transaction 操作以支持编辑数据,另外也可以加上 GetGmlObject/LockFeature
操作)关于服务涉及的基本元素,可以参考前面的章节:《服务涉及的基本元素》。
注意,在后面的内容中,服务的操作叧介绍 Basic WFS 和 Transaction WFS
中需要实现的操作,也就是说 GetCapabilities、DescribeFeatureType、
GetFeature 和 Transaction 操作。
GetCapabilities 操作
----------------------
1. KVP 格式请求
~~~~~~~~~~~~~~~
GetCapabilities 操作需要以下的参数:
+---------------------------+--------------------------+--------------------------+
| 参数 | 是否必须 | 默认值 |
+---------------------------+--------------------------+--------------------------+
| SERVICE | 是 | WFS |
+---------------------------+--------------------------+--------------------------+
| REQUEST=GetCapabilities | 是 | |
| | | |
| | | |
+---------------------------+--------------------------+--------------------------+
以下是一个 WFS 使用 KVP 格式的 GetCapabilities 操作示例:
::
http://www.someserver.com/wfs?
SERVICE=WFS&
REQUEST=GetCapabilities
2. XML 格式请求
~~~~~~~~~~~~~~~
以下是一个 WFS 使用 XML 格式的 GetCapabilities 操作示例:
::
3. 响应示例
~~~~~~~~~~~
以下是一个 WFS 的 GetCapabilities 操作的响应示例:
::
WFSows:ServiceType>
1.1.0ows:ServiceTypeVersion>
OGC Member WFSows:Title>
...
ows:ServiceIdentification>
BlueOxows:ProviderName>
...
ows:ServiceContact>
ows:ServiceProvider>
...
ows:Operation>
...
ows:Operation>
...
ows:Operation>
...
ows:Operation>
...
ows:Operation>
...
ows:Operation>
...
ows:Operation>
EPSG:4326ows:Value>
ows:Parameter>
10000ows:Value>
ows:Constraint>
...
ows:OperationsMetadata>
EPSG:62696405wfs:DefaultSRS>
text/xml; subtype=gml/3.1.1wfs:Format>
wfs:OutputFormats>
-180 -90ows:LowerCorner>
180 90ows:UpperCorner>
ows:WGS84BoundingBox>
...
wfs:FeatureType>
wfs:FeatureTypeList>
bo:OxTypewfs:Name>
Babe's Lineagewfs:Title>
text/xml; subtype=gml/3.1.1wfs:Format>
text/xhmtlwfs:Format>
wfs:OutputFormats>
wfs:GMLObjectType>
wfs:ServesGMLObjectTypeList>
gml:PointTypewfs:Name>
text/xml; subtype=gml/3.1.1wfs:Format>
text/xhtmlwfs:Format>
wfs:OutputFormats>
wfs:GMLObjectType>
...
wfs:SupportsGMLObjectTypeList>
gml:Envelopeogc:GeometryOperand>
gml:Pointogc:GeometryOperand>
gml:LineStringogc:GeometryOperand>
gml:Polygonogc:GeometryOperand>
...
ogc:GeometryOperands>
ogc:SpatialOperators>
ogc:Spatial_Capabilities>
LessThanogc:ComparisonOperator>
GreaterThanogc:ComparisonOperator>
LessThanEqualToogc:ComparisonOperator>
GreaterThanEqualToogc:ComparisonOperator>
EqualToogc:ComparisonOperator>
NotEqualToogc:ComparisonOperator>
Likeogc:ComparisonOperator>
Betweenogc:ComparisonOperator>
NullCheckogc:ComparisonOperator>
ogc:ComparisonOperators>
MINogc:FunctionName>
MAXogc:FunctionName>
SINogc:FunctionName>
COSogc:FunctionName>
TANogc:FunctionName>
ogc:FunctionNames>
ogc:Functions>
ogc:ArithmeticOperators>
ogc:Scalar_Capabilities>
ogc:Id_Capabilities>
ogc:Filter_Capabilities>
wfs:WFS_Capabilites>
DescribeFeatureType 操作
--------------------------
1. KVP 格式请求
~~~~~~~~~~~~~~~
DescribeFeatureType 操作需要以下的参数:
+-------------------------------+--------------------------+--------------------------+
| 参数 | 是否必须 | 默认值 |
+-------------------------------+--------------------------+--------------------------+
| VERSION | 是 | 1.1.0 |
+-------------------------------+--------------------------+--------------------------+
| SERVICE | 是 | WFS |
+-------------------------------+--------------------------+--------------------------+
| REQUEST=DescribeFeatureType | 是 | |
| | | |
| | | |
+-------------------------------+--------------------------+--------------------------+
| TYPENAME | | |
+-------------------------------+--------------------------+--------------------------+
| OUTPUTFORMAT | | text/xml; |
| | | subtype=gml/3.1.1 |
+-------------------------------+--------------------------+--------------------------+
以下是一个 WFS 使用 KVP 格式的 DescribeFeatureType 操作示例:
::
http://www.someserver.com/wfs?
SERVICE=WFS&
VERSION=1.1.0&
REQUEST=DescribeFeatureType&
TYPENAME=TreesA_1M,BuiltUpA_1M
2. XML 格式请求
~~~~~~~~~~~~~~~
以下是一个 WFS 使用 XML 格式的 DescribeFeatureType 操作示例:
::
<
TypeName
>
myns:PersonTypeName
>
DescribeFeatureType
>
3. 响应示例
~~~~~~~~~~~
以下是一个 WFS 的 DescribeFeatureType 操作的响应示例:
::
xml version="1.0" ?>
<
wfs
:FeatureCollection
xmlns
="http://www.someserver.com/myns"
xmlns
:myns
="http://www.someserver.com/myns"
xmlns
:wfs
="http://www.opengis.net/wfs"
xmlns
:gml
="http://www.opengis.net/gml"
xmlns
:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi
:schemaLocation
="http://www.opengis.net/wfs ../wfs/1.1.0/WFS.xsd
http://www.someserver.com/myns ex10.xsd">
10gml
:X >
10gml :Y >
gml
:coord
>
<
gml
:coord
>
<
gml
:X
>
20gml
:X
>
<
gml
:Y
>
20gml
:Y
>
gml
:coord
>
gml
:Envelope
>
gml
:boundedBy
>
<
gml
:featureMember
>
<
Person
>
<
myns
:lastName
>
Smithmyns
:lastName
>
<
myns
:firstName
>
Fredmyns
:firstName
>
<
myns
:age
>
35myns
:age
>
<
myns
:sex
>
Malemyns
:sex
>
<
myns
:location
>
<
gml
:Point
>
<
gml
:pos
>
15 15gml
:pos
>
gml
:Point
>
myns
:location
>
<
myns
:mailAddress
>
<
myns
:Address
>
<
myns
:streetName
>
Main St.myns
:streetName
>
<
myns
:streetNumber
>
5myns
:streetNumber
>
<
myns
:city
>
SomeCitymyns
:city
>
<
myns
:province
>
Someprovincemyns
:province
>
<
myns
:postalCode
>
X1X 1X1myns
:postalCode
>
<
myns
:country
>
Canadamyns
:country
>
<
myns
:Address
>
myns
:mailAddress
>
Person
>
gml
:featureMember
>
wfs
:FeatureCollection
>
GetFeature 操作
-----------------
1. KVP 格式请求
~~~~~~~~~~~~~~~
GetFeature 操作需要以下的参数:
+--------------------------+--------------------------+--------------------------+
| 参数 | 是否必须 | 默认值 |
+--------------------------+--------------------------+--------------------------+
| VERSION | 是 | 1.1.0 |
+--------------------------+--------------------------+--------------------------+
| SERVICE | 是 | WFS |
+--------------------------+--------------------------+--------------------------+
| REQUEST=GetFeature | 是 | |
+--------------------------+--------------------------+--------------------------+
| TYPENAME | 是 | |
+--------------------------+--------------------------+--------------------------+
| OUTPUTFORMAT | | text/xml; |
| | | subtype=gml/3.1.1 |
+--------------------------+--------------------------+--------------------------+
| BBOX | | |
+--------------------------+--------------------------+--------------------------+
| FILTER | | |
+--------------------------+--------------------------+--------------------------+
| SORTBY | | |
+--------------------------+--------------------------+--------------------------+
| MAXFEATURES | | |
+--------------------------+--------------------------+--------------------------+
| PROPERTYNAME | | |
+--------------------------+--------------------------+--------------------------+
| SRSNAME | | |
+--------------------------+--------------------------+--------------------------+
| FEATUREID | | |
+--------------------------+--------------------------+--------------------------+
| EXPIRY | | |
+--------------------------+--------------------------+--------------------------+
| RESULTTYPE | | results |
+--------------------------+--------------------------+--------------------------+
| FEATUREVERSION | | |
+--------------------------+--------------------------+--------------------------+
以下是一个WFS使用KVP格式的GetFeature操作示例:
::
http://www.someserver.com/wfs?
SERVICE=WFS&
VERSION=1.1.0&
REQUEST=GetFeature&
PROPERTYNAME=InWaterA_1M/wkbGeom,InWaterA_1M/tileId&
TYPENAME=InWaterA_1M&
FILTER=InWaterA_1M/wkbGeom
10,10
20 20
2.XML格式请求
~~~~~~~~~~~~~~~
以下是一个WFS使用XML格式的GetFeature操作示例:
::
xml version="1.0" ?>
<
DescribeFeatureType
version
="1.1.0"
service
="WFS"
outputFormat
="text/xml; subtype=gml/3.1.1"
xmlns
="http://www.opengis.net/wfs"
xmlns
:myns
="http://www.myserver.com/myns"
xmlns
:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi
:schemaLocation
="http://www.opengis.net/wfs ../wfs/1.1.0/WFS.xsd"
>
<
TypeName
>
myns:PersonTypeName
>
DescribeFeatureType
>
3.响应示例
~~~~~~~~~~~
以下是一个WFS的GetFeature操作的响应示例:
::
xml version="1.0" ?>
<
wfs
:FeatureCollection
xmlns
="http://www.someserver.com/myns"
xmlns
:myns
="http://www.someserver.com/myns"
xmlns
:wfs
="http://www.opengis.net/wfs"
xmlns
:gml
="http://www.opengis.net/gml"
xmlns
:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi
:schemaLocation
="http://www.opengis.net/wfs ../wfs/1.1.0/WFS.xsd
http://www.someserver.com/myns ex10.xsd"
>
<
gml
:boundedBy
>
<
gml
:Envelope
>
<
gml
:coord
>
<
gml
:X
>
10gml
:X
>
<
gml
:Y
>
10gml
:Y
>
gml
:coord
>
<
gml
:coord
>
<
gml
:X
>
20gml
:X
>
<
gml
:Y
>
20gml
:Y
>
gml
:coord
>
gml
:Envelope
>
gml
:boundedBy
>
<
gml
:featureMember
>
<
Person
>
<
myns
:lastName
>
Smithmyns
:lastName
>
<
myns
:firstName
>
Fredmyns
:firstName
>
<
myns
:age
>
35myns
:age
>
<
myns
:sex
>
Malemyns
:sex
>
<
myns
:location
>
<
gml
:Point
>
<
gml
:pos
>
15 15gml
:pos
>
gml
:Point
>
myns
:location
>
<
myns
:mailAddress
>
<
myns
:Address
>
<
myns
:streetName
>
Main St.myns
:streetName
>
<
myns
:streetNumber
>
5myns
:streetNumber
>
<
myns
:city
>
SomeCitymyns
:city
>
<
myns
:province
>
Someprovincemyns
:province
>
<
myns
:postalCode
>
X1X 1X1myns
:postalCode
>
<
myns
:country
>
Canadamyns
:country
>
<
myns
:Address
>
myns
:mailAddress
>
Person
>
gml
:featureMember
>
wfs
:FeatureCollection
>
Transaction 操作
------------------
1. KVP 格式请求
~~~~~~~~~~~~~~~
Transaction 操作使用 KVP 格式请求目前叧支持 Delete(Insert 和 Update
必须通过 XML 格式请求发送)。Transaction 操作需要以下的参数:
+--------------------------+--------------------------+--------------------------+
| 参数 | 是否必须 | 默认值 |
+--------------------------+--------------------------+--------------------------+
| VERSION | 是 | 1.1.0 |
+--------------------------+--------------------------+--------------------------+
| SERVICE | 是 | WFS |
+--------------------------+--------------------------+--------------------------+
| REQUEST=Transaction | 是 | |
+--------------------------+--------------------------+--------------------------+
| OPERATION=Delete | 是 | |
+--------------------------+--------------------------+--------------------------+
| TYPENAME | 是 | |
+--------------------------+--------------------------+--------------------------+
| RELEASEACTION | | |
+--------------------------+--------------------------+--------------------------+
| FILTER | | |
+--------------------------+--------------------------+--------------------------+
| BBOX | | |
+--------------------------+--------------------------+--------------------------+
| FEATUREID | | |
+--------------------------+--------------------------+--------------------------+
以下是一个WFS使用KVP格式的Transaction操作示例:
::
http://www.someserver.com/wfs?
SERVICE=WFS&
VERSION=1.1.0&
REQUEST=Transaction&
OPERATION=Delete&
TYPENAME=InWaterA_1M,BuiltUpA_1M&
FILTER=(InWaterA_1M/wkbGeom
10 10
20 20
)(< Filter>BuiltUpA_1M/wkbGeom
10 10
20,20
)
2.XML格式请求
~~~~~~~~~~~~~~~
以下是一个WFS使用XML格式的Transaction操作示例:
::
Highway 401
SEG_A41
...
Asphalt
12
15
RoadL_1M/segment/designation
SEG_A60
RoadL_1M/segment/designation
SEG_A60
SEG_A69
3.响应示例
~~~~~~~~~~~
以下是一个WFS的Transaction操作的响应示例:
::
1
1
1
ArcGISServer对WFS的支持
-----------------------------
ArcGISServer10中支持的WFS版本为最新的1.1.0。
在ArcGISServer 中,叧需简单地勾选的Capabilities选项卡中可以选择支持WFS,
如图 19。
如果勾选了Transaction复选框,那么通过该 WFS 还可以进行数据更新(注意,需要是SDE数据源)。
|image0|
图19 ArcGISServer发布WFS服务
现在我们在浏览器中执行一个GetFeature操作,查询名为“Beijing”的对象:
::
http://localhost:8399/arcgis/services/test/wfsTest/MapServer/WFSServer?
request=getfeature&
typename=test_wfsTest:sde_cities&
filter=(
CITY_NAME
Beijing
)
这个操作返回如下的结果:
::
-86.002616990000007
-176.15156363599999
102.93161888100001
179.22188769499999
474
Beijing
CHN-BJN
Beijing
CH
China
National and provincial capital
1
5,000,000 and greater
0
1
40
185.74736243999999
39.906189088000019 116.38803663600004
接着,我想删掉这个对象,就要使用 Transaction 操作。在 ArcGISServer 中,执行删除之前还需要 lockId 属性,
因此还需要通过 GetFeatureWithLock 操作获取一个锁:
::
http://localhost:8399/arcgis/services/test/wfsTest/MapServer/WFSServer?
request=getfeaturewithlock&
typename=test_wfsTest:sde_cities&
filter=(
CITY_NAME
Beijing
)
这个操作返回lockId值为"{CEBC222E-00AD-49F5-A0E9-9F4CB98EE07E}",接下来,我们通过一个POST请求对这个对象进行删除,请求体内容如下:
::
{CEBC222E-00AD-49F5-A0E9-9F4CB98EE07E}
删除成功后将会返回如下的结果:
::
1
我们也可以在其它的客户端中直接加载这个WFS服务,比如使用uDig:
|image1|
图20uDig中加载ArcGISServer发布的WFS服务
.. |image0| image:: image083_xpe.jpg
.. |image1| image:: image085_xcf.jpg
.. [18] OGC Common Query Language,参考《OGC Catalogue Service 2.0.2》标准的 6.2 章节。