请求参数

Transaction 操作通过 POST 请求实现添加要素、更新要素、删除要素三个功能,请求体采用 XML 格式,主要节点要素介绍如下:

表1 Transaction 操作请求体节点元素

请求参数

是否必需

描述

<Transaction>

是

一个 Transaction 要素包括0个或多个用于添加、更新、删除要素的<Insert>、<Update> 或 <Delete> 元素。

允许<Transaction>元素为空,即不包含其他元素,这时 Transaction 操作没有意义。

<Insert>

否

进行添加要素操作时必选。 待添加的要素需要通过<feature>元素用 GML 语言进行描述。 可在一个<Insert>元素中添加多个要素。

<Update>

否

进行更新要素操作时必选。其中,typeName 参数来指定需要更新的要素的类型。 一个<Update>元素中可包含一个或多个<Property>元素,用于指定需要更新的要素的属性(<Name>元素)和属性值(<Value>元素),没有<Value>元素时该属性将被赋予空值。 <Update>元素中还包含<Filter>元素,用于限定待更新要素的范围,可以是一个或多个,详见请求示例。

<Delete>

否

进行删除要素操作时必选。其中,typeName 参数来指定需要删除的要素的类型。 通过<Filter>元素指定待删除的要素,可以是一个或多个。

请求示例

本示例中对 WFS 服务 data-world/wfs100进行了3次 Transaction 操作,先添加一个新要素,然后对此要素进行更新,最后把这个要素删除。即对 http://localhost:8090/iserver/services/data-World/wfs100?request=Transaction ,执行 POST 请求,分别传输以下请求体:

  1. 添加要素

执行 POST 请求,在 World:Capitals 图层创建名为 testCapital 的示例首都,请求体为:

<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs"

        service="WFS" version="1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd https://www.supermap.com/World http://localhost:8090/iserver/services/data-World/wfs100?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=World:Capitals">

        <wfs:Insert>

                <World:Capitals xmlns:World="https://www.supermap.com/World">

                        <World:CAPITAL>testCapital</World:CAPITAL>

                        <World:COUNTRY>testCountry</World:COUNTRY>

                        <World:the_geom>

                                <gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">

                                        <gml:coordinates>143.09,35.57</gml:coordinates>

                                </gml:Point>

                        </World:the_geom>

                </World:Capitals>

        </wfs:Insert>

</wfs:Transaction>

添加要素成功后,响应参见:响应示例。

  1. 更新要素

执行 POST 请求,将 testCountry 国家的首都修改为 “otherCapital”, 请求体为:

<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs"

        service="WFS" version="1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd https://www.supermap.com/World http://localhost:8090/iserver/services/data-world/wfs100?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=World:Capitals">

        <wfs:Update typeName="World:Capitals" xmlns:World="https://www.supermap.com/World">

                <wfs:Property>

                        <wfs:Name>CAPITAL</wfs:Name>

                        <wfs:Value>otherCapital</wfs:Value>

                </wfs:Property>

                <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">

                        <ogc:PropertyIsEqualTo>

                                <ogc:PropertyName>COUNTRY</ogc:PropertyName>

                                <ogc:Literal>testCountry</ogc:Literal>

                        </ogc:PropertyIsEqualTo>

                </ogc:Filter>

        </wfs:Update>

</wfs:Transaction>

更新要素成功后,响应参见:响应示例。

  1. 删除要素

执行 POST 请求,将 World:Capitals 图层中 CAPITAL 字段名为 “otherCapital”的要素删除,请求体为:

<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs"

        service="WFS" version="1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd https://www.supermap.com/World http://localhost:8090/iserver/services/data-world/wfs100?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=World:Capitals">

        <wfs:Delete typeName="feature:Capitals" xmlns:feature="https://www.supermap.com/World">

                <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">

                        <ogc:PropertyIsEqualTo>

                                <ogc:PropertyName>CAPITAL</ogc:PropertyName>

                                <ogc:Literal>otherCapital</ogc:Literal>

                        </ogc:PropertyIsEqualTo>

                </ogc:Filter>

        </wfs:Delete>

</wfs:Transaction>

删除要素成功后,响应参见:响应示例。

4. 添加含岛洞的要素

执行 POST 请求,在 ChongQing:City 图层创建一个岛洞多边形要素,请求体为:

<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml"
        service="WFS" version="1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd https://www.supermap.com/DataSource http://172.16.120.157:8499/iserver/services/data-WorkSpace/wfs100?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=ChongQing:City">
        <wfs:Insert>
                <ChongQing:City xmlns:ChongQing="https://www.supermap.com/ChongQing">
                        <ChongQing:the_geom>
                                <gml:Polygon>
                               <gml:outerBoundaryIs>
                                 <gml:LinearRing>
                                   <gml:coordinates>108.46641599600281,-17.489768467768315 147.63474980294149,-17.489768467768315 147.63474980294149,-49.04203736780222 97.58632327185319,-56.29543251723529 92.87161642472168,-45.052670035614014 108.46641599600281,-17.489768467768315</gml:coordinates>
                                 </gml:LinearRing>
                              </gml:outerBoundaryIs>
                             <gml:innerBoundaryIs>
                               <gml:LinearRing>
                                 <gml:coordinates>117.89582969026583,-30.183209979276185 117.17049017532253,-40.70063294595417 134.21596877649023,-35.26058658387936 117.89582969026583,-30.183209979276185</gml:coordinates>
                               </gml:LinearRing>
                             </gml:innerBoundaryIs>
                            </gml:Polygon>
                        </ChongQing:the_geom>
                </ChongQing:City>
        </wfs:Insert>
</wfs:Transaction>

添加要素成功后,响应参见:响应示例。

执行 POST 请求,在 ChongQing:City 图层创建一组岛洞多边形要素,请求体为:

 <wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml"
        service="WFS" version="1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd https://www.supermap.com/DataSource http://172.16.120.157:8499/iserver/services/data-WorkSpace/wfs100?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=ChongQing:City">
        <wfs:Insert>
                <ChongQing:City xmlns:ChongQing="https://www.supermap.com/ChongQing">
                         <ChongQing:the_geom>
                         <gml:MultiPolygon>
                               <gml:polygonMember>
                                <gml:Polygon>
                               <gml:outerBoundaryIs>
                                 <gml:LinearRing>
                                   <gml:coordinates>116.0,39.0 116.1,39.0 116.1,39.1 116.0,39.1 116.0,39.0</gml:coordinates>
                                 </gml:LinearRing>
                              </gml:outerBoundaryIs>
                             <gml:innerBoundaryIs>
                               <gml:LinearRing>
                                 <gml:coordinates>116.02,39.02 116.08,39.02 116.08,39.08 116.02,39.08 116.02,39.02</gml:coordinates>
                               </gml:LinearRing>
                             </gml:innerBoundaryIs>
                            </gml:Polygon>
                           </gml:polygonMember>
                            <gml:polygonMember>
                                <gml:Polygon>
                               <gml:outerBoundaryIs>
                                 <gml:LinearRing>
                                   <gml:coordinates>117.0,39.0 117.1,39.0 117.1,39.1 117.0,39.1 117.0,39.0</gml:coordinates>
                                 </gml:LinearRing>
                              </gml:outerBoundaryIs>
                             <gml:innerBoundaryIs>
                               <gml:LinearRing>
                                 <gml:coordinates>117.02,39.02 117.08,39.02 117.08,39.08 117.02,39.08 117.02,39.02</gml:coordinates>
                               </gml:LinearRing>
                             </gml:innerBoundaryIs>
                            </gml:Polygon>
                           </gml:polygonMember>
                         </gml:MultiPolygon>
                        </ChongQing:the_geom>
                </ChongQing:City>
        </wfs:Insert>
</wfs:Transaction>

 

添加要素成功后,响应与添加单个要素结果类似,不再赘述。