流程链接

WPS的一个好处是它本身能够链接流程。与函数如何调用其他函数类似,WPS进程可以将另一个进程的输出用作其输入。因此,许多复杂的函数可以组合成一个强大的请求。

例如,让我们取一些随GeoServer提供的示例数据,并使用WPS引擎链接一些内置流程,这将允许用户动态执行地理空间分析。

在这个例子中,我们要回答的问题是:有多少英里的道路穿过保护区?

将用于此示例的数据包含在geoserver的标准安装中:

  • sf:roads :包含道路信息的图层

  • sf:restricted :表示限制区域的层

限制区部分与道路重叠。我们想知道限制区内道路的总长度,如下一个屏幕截图所示。道路网以白色表示,与假彩色DEM(数字高程模型)相对应。限制区域用深棕色虚线表示。限制区内的路网部分用红色绘制。

../../../_images/spearfish.png

限制区内道路总长

为了计算总长度,我们需要以下内置的WPS流程:

  • gs:IntersectionFeatureCollection :返回两个要素集合之间的交集,同时添加两个要素集合的属性

  • gs:CollectGeometries :收集要素集合中的所有默认几何图形,并将其作为单个几何图形集合返回

  • JTS:length :以与几何图形相同的度量单位计算几何图形的长度

执行这些进程的顺序很重要。我们要做的第一件事是将公路网与限制区相交。这为我们提供了包含我们感兴趣的所有道路的要素集合。然后,我们将这些几何图形收集到单个GeometryCollection中,以便可以使用内置的JTS算法来计算长度。

gs:IntersectionFeatureCollection --> gs:CollectGeometries --> JTS:length

过程序列通过将第一个过程嵌入到第二个过程、第二个过程嵌入到第三个过程等来确定如何构建WPS请求。一个过程产生一些输出,这些输出将成为下一个过程的输入,从而形成一个处理管道,可以解决复杂的空间分析问题。具有单个HTTP请求。使用geoserver的层的好处是数据不会在进程之间来回传递,从而产生非常好的性能。

以下是XML格式的完整WPS请求:

<?xml version="1.0" encoding="UTF-8"?>
<wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wps/1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wcs="http://www.opengis.net/wcs/1.1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">

  <ows:Identifier>JTS:length</ows:Identifier>
  <wps:DataInputs>
    <wps:Input>
      <ows:Identifier>geom</ows:Identifier>
      <wps:Reference mimeType="text/xml; subtype=gml/3.1.1"
                      xlink:href="http://geoserver/wps" method="POST">
      <wps:Body>
        <wps:Execute version="1.0.0" service="WPS">
          <ows:Identifier>gs:CollectGeometries</ows:Identifier>
          <wps:DataInputs>
            <wps:Input>
              <ows:Identifier>features</ows:Identifier>
              <wps:Reference mimeType="text/xml; subtype=wfs-collection/1.0" xlink:href="http://geoserver/wps" method="POST">
                <wps:Body>
                  <wps:Execute version="1.0.0" service="WPS">
                    <ows:Identifier>gs:IntersectionFeatureCollection</ows:Identifier>
                    <wps:DataInputs>
                      <wps:Input>
                        <ows:Identifier>first feature collection</ows:Identifier>
                        <wps:Reference mimeType="text/xml; subtype=wfs-collection/1.0" xlink:href="http://geoserver/wfs" method="POST">
                          <wps:Body>
                            <wfs:GetFeature service="WFS" version="1.0.0" outputFormat="GML2">
                              <wfs:Query typeName="sf:roads"/>
                            </wfs:GetFeature>
                          </wps:Body>
                        </wps:Reference>
                      </wps:Input>
                      <wps:Input>
                        <ows:Identifier>second feature collection</ows:Identifier>
                        <wps:Reference mimeType="text/xml; subtype=wfs-collection/1.0" xlink:href="http://geoserver/wfs" method="POST">
                          <wps:Body>
                            <wfs:GetFeature service="WFS" version="1.0.0" outputFormat="GML2">
                              <wfs:Query typeName="sf:restricted"/>
                            </wfs:GetFeature>
                          </wps:Body>
                        </wps:Reference>
                      </wps:Input>
                      <wps:Input>
                        <ows:Identifier>first attributes to retain</ows:Identifier>
                        <wps:Data>
                          <wps:LiteralData>the_geom cat</wps:LiteralData>
                        </wps:Data>
                      </wps:Input>
                      <wps:Input>
                        <ows:Identifier>second attributes to retain</ows:Identifier>
                        <wps:Data>
                          <wps:LiteralData>cat</wps:LiteralData>
                        </wps:Data>
                      </wps:Input>
                    </wps:DataInputs>
                    <wps:ResponseForm>
                      <wps:RawDataOutput mimeType="text/xml;
                                         subtype=wfs-collection/1.0">
                        <ows:Identifier>result</ows:Identifier>
                      </wps:RawDataOutput>
                    </wps:ResponseForm>
                  </wps:Execute>
                </wps:Body>
              </wps:Reference>
            </wps:Input>
          </wps:DataInputs>
          <wps:ResponseForm>
            <wps:RawDataOutput mimeType="text/xml; subtype=gml/3.1.1">
              <ows:Identifier>result</ows:Identifier>
            </wps:RawDataOutput>
          </wps:ResponseForm>
        </wps:Execute>
      </wps:Body>
    </wps:Reference>
    </wps:Input>
  </wps:DataInputs>
  <wps:ResponseForm>
    <wps:RawDataOutput>
      <ows:Identifier>result</ows:Identifier>
    </wps:RawDataOutput>
  </wps:ResponseForm>
</wps:Execute>

您可以将这个XML请求保存在一个名为wps-chaining.xml的文件中,并使用curl执行请求,如下所示:

curl-u admin:geoserver-h'内容类型:xml'-xpost-d@'wps-chaining.xml'http://localhost:8080/geoserver/wps

反应只是一个数字,即与限制区相交的道路总长度,应该在 25076.285 米(长度过程返回地图单位)

要查看正在运行的WPS请求,可以使用内置的 WPS请求生成器 .