GeoServer中的WPS服务


title: GeoServer中的WPS服务
date: 2021-05-10
author: ac
tags:

  • WPS

categories:

  • GIS

本文中示例使用的是GeoServer 服务器,所以请先安装好GeoServer对WPS服务的扩展模块

1. WPS简介

Web Processing Service(WPS)最初被称为Geoprocessing Service。在其发展初期,该名称被改为Web Processing Service,以避免首字母缩写GPS,因为这可能会与全球定位系统(Global Positioning System)这个缩写的传统用法相混淆。

自从WPS成为OGC的规范以来,术语geospatial变得有点冗余。

WPS定义了一个标准化接口,该接口有助于发布(Publishing)地理处理的流程(Processes),以及客户机发现和绑定这些流程。

  • Processes:这些流程包括任何运行在空间参考数据上的算法,计算和模型。
  • Publishing:发布意味着提供机器可读的绑定信息以及人类可读的元数据,从而允许服务被发现和使用。

WPS可以通过网络为客户端配置和提供任何类型的GIS功能。

Web处理服务(WPS)向客户端提供对预先编程的空间数据进行操作的计算模型的访问。服务所需的数据可以通过网络传递,也可以在服务器上获取。这些数据可以是使用图像数据格式或数据交换标准,如GML。计算可以是简单到从一组空间参考数据中减去另一组数据(例如,确定两个不同季节流感病例的差异),也可以是复杂到全球气候变化的模型。

在网络上实现地理空间处理需要开发各种各样的web服务来支持原子地理空间操作以及复杂的建模能力。标准化这些流程的调用方式非常重要,以减少所需的编程量,并促进新服务的实现和采用。WPS旨在帮助OGC成员实现这些目标。

2. WPS 操作

WPS接口指定了客户端可以请求并由WPS服务器执行的三种操作,这些操作都是所有服务器必须实现的。操作如下:

  • GetCapabilities :此操作允许客户端请求并接收描述服务器实现能力的服务元数据(或能力)文档。GetCapabilities操作提供了WPS实例提供的每个进程的名称和一般描述。
  • DescribeProcess :此操作允许客户端请求并接收关于可在服务实例上运行的流程的详细信息,包括所需的输入、允许的格式和可生成的输出。
  • Execute :此操作允许客户端运行由WPS实现的指定进程,使用提供的输入参数值并返回生成的输出

这些操作与其他OGC Web服务(WMS、WFS、WCS)有许多相似之处。OWS规范中指定了与这些其他OpenGIS Web Services共同的接口。

image-20210510175110349

从上面的类图可以看到WPS服务也实现了OWS接口,所以也遵循OWS规范中的请求和响应相关的规则。

每个server服务只实例化该服务类一个实例对象,当服务可用时,该对象始终存在。

举个栗子,考虑一个简单的Process流程:求两个面的交集(intersect)。

  • GetCapabilities请求返回的结果可以查看该WPS服务是否支持intersect操作,以及操作的限制,如intersect仅限于一个多边形与另一个多边形相交;
  • DescribeProcess请求返回的结果可以查看到intersect流程需要两个输入,"FirstPolygon"和"SecondPolygon"需要是GML2.2版本的面要素,结果还描述了WPS服务的输出结果和版本格式(GML2.2或GML3.1),它可以作为Web可访问资源进行传输;
  • 客户端将通过调用Execute操作来运行流程,并且可以选择将提供的两个输入多边形直接嵌入在请求中,并确定输出应该作为web可访问的资源存储。

完成后,流程将返回一个ExecuteResponse XML文档,该文档标识输入和输出,指示流程是否成功执行,如果成功,则包含对web可访问资源的引用。

image-20210511111129140

上述表格是WPS各操作支持的请求编码格式。

2.1 GetCapabilities

GetCapabilities操作允许客户端从服务器检索服务元数据。

对GetCapabilities请求的响应应该是一个XML文档,其中包含关于服务器的服务元数据,包括描述所有已实现的Process进程的简短元数据,以及描述其功能。

GetCapabilities操作请求参数:

namemultiplicity
serviceOne(mandatory)
RequestOne(mandatory)
AcceptVersionsZero or one(optional)
languageZero or one(optional)

示例:

KVP的形式

http://localhost:8080/geoserver/wps?service=WPS&Request=GetCapabilities&AcceptVersions=1.0.0

GeoServer 安装完WPS扩展后,发起上述请求,可以得到下面结果。

注意:WPS扩展模块实现的是WPS1.0.0规范

XML文本的形式

请求URL:http://localhost:8080/geoserver/ows或http://localhost:8080/geoserver/wps

请求数据:

<?xml version="1.0" encoding="UTF-8"?>
<wps:GetCapabilities language="cz" service="WPS" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_request.xsd">
  <wps:AcceptVersions>
    <ows:Version>1.0.0</ows:Version>
  </wps:AcceptVersions>
</wps:GetCapabilities>

image-20210512105312901

响应示例

<?xml version="1.0" encoding="UTF-8"?>
<wps:Capabilities xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
    <ows:ServiceIdentification>
        <ows:Title>Prototype GeoServer WPS</ows:Title>
        <ows:Abstract/>
        <ows:ServiceType>WPS</ows:ServiceType>
        <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
    </ows:ServiceIdentification>
    <ows:ServiceProvider>
        <ows:ProviderName>The Ancient Geographers</ows:ProviderName>
        <ows:ProviderSite xlink:href="http://geoserver.org"/>
        <ows:ServiceContact/>
    </ows:ServiceProvider>
    <ows:OperationsMetadata>
        <ows:Operation name="GetCapabilities">
            <ows:DCP>
                <ows:HTTP>
                    <ows:Get xlink:href="http://localhost:8080/geoserver/wps"/>
                    <ows:Post xlink:href="http://localhost:8080/geoserver/wps"/>
                </ows:HTTP>
            </ows:DCP>
        </ows:Operation>
        <ows:Operation name="DescribeProcess">
            <ows:DCP>
                <ows:HTTP>
                    <ows:Get xlink:href="http://localhost:8080/geoserver/wps"/>
                    <ows:Post xlink:href="http://localhost:8080/geoserver/wps"/>
                </ows:HTTP>
            </ows:DCP>
        </ows:Operation>
        <ows:Operation name="Execute">
            <ows:DCP>
                <ows:HTTP>
                    <ows:Get xlink:href="http://localhost:8080/geoserver/wps"/>
                    <ows:Post xlink:href="http://localhost:8080/geoserver/wps"/>
                </ows:HTTP>
            </ows:DCP>
        </ows:Operation>
    </ows:OperationsMetadata>
    <wps:ProcessOfferings>
        <wps:Process wps:processVersion="1.0.0">
            <ows:Identifier>JTS:area</ows:Identifier>
            <ows:Title>Area</ows:Title>
            <ows:Abstract>Returns the area of a geometry, in the units of the geometry. Assumes a Cartesian plane, so this process is only recommended for non-geographic CRSes.</ows:Abstract>
        </wps:Process>
        <wps:Process wps:processVersion="1.0.0">
            <ows:Identifier>JTS:boundary</ows:Identifier>
            <ows:Title>Boundary</ows:Title>
            <ows:Abstract>Returns a geometry boundary. For polygons, returns a linear ring or multi-linestring equal to the boundary of the polygon(s). For linestrings, returns a multipoint equal to the endpoints of the linestring. For points, returns an empty geometry collection.</ows:Abstract>
        </wps:Process>
        <wps:Process wps:processVersion="1.0.0">
            <ows:Identifier>JTS:buffer</ows:Identifier>
            <ows:Title>Buffer</ows:Title>
            <ows:Abstract>Returns a polygonal geometry representing the input geometry enlarged by a given distance around its exterior.</ows:Abstract>
        </wps:Process>
        <wps:Process wps:processVersion="1.0.0">
            <ows:Identifier>JTS:centroid</ows:Identifier>
            <ows:Title>Centroid</ows:Title>
            <ows:Abstract>Returns the geometric centroid of a geometry. Output is a single point.  The centroid point may be located outside the geometry.</ows:Abstract>
        </wps:Process>
        ...
    </wps:ProcessOfferings>  
    <wps:Languages>
        <wps:Default>
            <ows:Language>en-US</ows:Language>
        </wps:Default>
        <wps:Supported>
            <ows:Language>en-US</ows:Language>
        </wps:Supported>
    </wps:Languages>
</wps:Capabilities>

响应结果分析:

  • Service Identification:关于服务的元数据,服务类型和版本。
  • OperationsMetadata:关于服务支持的由服务器端实现的操作的元数据信息,包括用于操作请求的url。
  • ProcessOfferings:提供服务器端已经实现了的Process进程的简要描述的无序列表。

2.2 DescribeProcess

DescribeProcess操作允许WPS客户端请求可由Execute操作执行的一个或多个进程的完整描述。这个描述包括输入和输出参数和格式。此描述可用于自动构建用户界面,以捕获用于执行流程实例的参数值。

DescribeProcess操作请求的参数:

namedescirptionm/o
service服务类型,值是"WPS"m
request操作名称,值为"DescribeProcess"m
version操作的版本,不能为空,值由每个WPS实现的规范和模式版本决定m
language语言标识o
IdentifierProcess流程的标识m

示例:

KVP的形式

http://localhost:8080/geoserver/wps?service=WPS&Request=DescribeProcess&version=1.0.0&language=en-US&Identifier=JTS:centroid,JTS:buffer

多个Process流程用,号隔开

XML文本的形式

请求URL地址:http://localhost:8080/geoserver/ows

<?xml version="1.0" encoding="UTF-8"?>
<DescribeProcess service="WPS" version="1.0.0" xmlns="http://www.opengis.net/wps/1.0.0" 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">
    <ows:Identifier>JTS:buffer</ows:Identifier>
    <ows:Identifier>JTS:centroid</ows:Identifier>
</DescribeProcess>

image-20210512113327747

statusSupported="true"表示该Process流程支持异步请求,服务器也会持续更新Process流程的状态,与存储在ExecuteResponseXML文档中Process状态的值一致。客户机可以通过GetExecutions查看Process状态。

响应结果

响应的XML文档包含有关每个请求的Process流程的元数据,包含以下内容:

  • Process流程名称、标题和摘要
  • 对每个输入和输出参数:标识符、标题、摘要、多重性以及支持的数据类型和格式
<?xml version="1.0" encoding="UTF-8"?>
<wps:ProcessDescriptions xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
    <ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true">
        <ows:Identifier>JTS:centroid</ows:Identifier>
        <ows:Title>Centroid</ows:Title>
        <ows:Abstract>Returns the geometric centroid of a geometry. Output is a single point.  The centroid point may be located outside the geometry.</ows:Abstract>
        <DataInputs>
            <Input maxOccurs="1" minOccurs="1">
                <ows:Identifier>geom</ows:Identifier>
                <ows:Title>geom</ows:Title>
                <ows:Abstract>Input geometry</ows:Abstract>
                <ComplexData>
                    <Default>
                        <Format>
                            <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
                        </Format>
                    </Default>
                    <Supported>
                        <Format>
                            <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
                        </Format>
                        <Format>
                            <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/wkt</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/gml-3.1.1</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/gml-2.1.2</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/json</MimeType>
                        </Format>
                    </Supported>
                </ComplexData>
            </Input>
        </DataInputs>
        <ProcessOutputs>
            <Output>
                <ows:Identifier>result</ows:Identifier>
                <ows:Title>result</ows:Title>
                <ComplexOutput>
                    <Default>
                        <Format>
                            <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
                        </Format>
                    </Default>
                    <Supported>
                        <Format>
                            <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
                        </Format>
                        <Format>
                            <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/wkt</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/gml-3.1.1</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/gml-2.1.2</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/json</MimeType>
                        </Format>
                    </Supported>
                </ComplexOutput>
            </Output>
        </ProcessOutputs>
    </ProcessDescription>
    <ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true">
        <ows:Identifier>JTS:buffer</ows:Identifier>
        <ows:Title>Buffer</ows:Title>
        <ows:Abstract>Returns a polygonal geometry representing the input geometry enlarged by a given distance around its exterior.</ows:Abstract>
        <DataInputs>
            <Input maxOccurs="1" minOccurs="1">
                <ows:Identifier>geom</ows:Identifier>
                <ows:Title>geom</ows:Title>
                <ows:Abstract>Input geometry</ows:Abstract>
                <ComplexData>
                    <Default>
                        <Format>
                            <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
                        </Format>
                    </Default>
                    <Supported>
                        <Format>
                            <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
                        </Format>
                        <Format>
                            <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/wkt</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/gml-3.1.1</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/gml-2.1.2</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/json</MimeType>
                        </Format>
                    </Supported>
                </ComplexData>
            </Input>
            <Input maxOccurs="1" minOccurs="1">
                <ows:Identifier>distance</ows:Identifier>
                <ows:Title>distance</ows:Title>
                <ows:Abstract>Distance to buffer the input geometry, in the units of the geometry</ows:Abstract>
                <LiteralData>
                    <ows:DataType>xs:double</ows:DataType>
                    <ows:AnyValue/>
                </LiteralData>
            </Input>
            <Input maxOccurs="1" minOccurs="0">
                <ows:Identifier>quadrantSegments</ows:Identifier>
                <ows:Title>quadrantSegments</ows:Title>
                <ows:Abstract>Number determining the style and smoothness of buffer corners. Positive numbers create round corners with that number of segments per quarter-circle, 0 creates flat corners.</ows:Abstract>
                <LiteralData>
                    <ows:DataType>xs:int</ows:DataType>
                    <ows:AnyValue/>
                </LiteralData>
            </Input>
            <Input maxOccurs="1" minOccurs="0">
                <ows:Identifier>capStyle</ows:Identifier>
                <ows:Title>capStyle</ows:Title>
                <ows:Abstract>Style for the buffer end caps. Values are: Round - rounded ends (default), Flat - flat ends; Square - square ends.</ows:Abstract>
                <LiteralData>
                    <ows:AllowedValues>
                        <ows:Value>Round</ows:Value>
                        <ows:Value>Flat</ows:Value>
                        <ows:Value>Square</ows:Value>
                    </ows:AllowedValues>
                </LiteralData>
            </Input>
        </DataInputs>
        <ProcessOutputs>
            <Output>
                <ows:Identifier>result</ows:Identifier>
                <ows:Title>result</ows:Title>
                <ComplexOutput>
                    <Default>
                        <Format>
                            <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
                        </Format>
                    </Default>
                    <Supported>
                        <Format>
                            <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
                        </Format>
                        <Format>
                            <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/wkt</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/gml-3.1.1</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/gml-2.1.2</MimeType>
                        </Format>
                        <Format>
                            <MimeType>application/json</MimeType>
                        </Format>
                    </Supported>
                </ComplexOutput>
            </Output>
        </ProcessOutputs>
    </ProcessDescription>
</wps:ProcessDescriptions>
  • ProcessDescription:Process流程的完整信息的描述,包含流程标识Identifier、输入参数类型DataInputs、输出参数ProcessOutputs以及数据格式类型和约束等。
  • ComplexData:复合数据类型,表示该数据是Supported标签内支持的数据类型中的组合。
  • LiteralData:文字数据,可以是任何文本字符串。用于传递单个参数,如数字和文本参数(数据类型常是整数、浮点、字符串)

2.3 Execute

Execute操作允许WPS客户机运行由服务器实现的指定Process流程,使用提供的输入参数值并返回生成的输出值。

  • 输入参数可以直接包含在Execute请求中,或者引用web可访问的资源。
  • 输出可以以XML响应文档的形式返回,可以嵌入在响应文档中,也可以作为web可访问资源存储。

如果存储输出,则响应结果应该为包含每个存储输出的URL的XML文档,这样客户机可以使用这些URL来检索那些输出。或者,对于单个输出,可以指示服务器返回原始形式的输出,而不需要包装在XML响应文档中。

Execute请求参数:

namedescriptionm/o
service服务类型标识,值为"WPS"m
request操作名称,值为"Execute"m
version服务版本,不能为空m
IdentifierProcess流程的标识m
DataInputs执行Process需要的输入参数o
Response FormProcess结果的响应格式(Raw data or XML)o
language语言标识o

操作请求提供对多个输入的支持。每个输入都引用单个Execute请求可能需要的一种输入形式。

向WPS提供大型输入的通常方法是提供一个或多个输入值的uri(通常是url),除非输入是简单标量值。这不是用来促进批处理的(例如,通过一个算法处理多个图像)。如果一个流程要运行多次(可能每次使用不同的输入),那么每次运行都应作为单独的Execute操作的请求来提交。

java中标量可以理解为是Date、String、基本类型等。

注意,Process的输入和输出是无序的。当一个Process需要大量输入或有较多输出数据时,服务端或客户端花在数据解析上的时间会很多,所以建议接口实现者以一种有效的方式打包和对输入/输出进行排序,并在Process流程描述中确定这个最佳排序需求。

数据输入类型的数据结构

InputType data structure
namedescriptiondata typem/o
Identifierwps服务标识ows:CodeTypem
Title标题字符类型o
Abstract简介字符类型o
InputData Form Choice数据表单详见下表m
InputData Form Choice
namedescriptionMultiplicitydata type
Reference将输入数据标识为web可访问的资源,并引用该资源Zero or oneInputReference
Data将此输入数据标识为封装在Execute请求中Zero or oneDataType

InputReference类型更多的是使用URL引用Web资源,可以指定href属性和method属性来标识资源和请求资源的方式。

DataType类型是之前介绍的ComplexDataLiteralData,以及BoundingBoxData

BoundingBoxData是指定两对坐标(用于2d和3d空间)描述边界的矩形,使用左下角(最小值)和右上角(最大值)的坐标、空间参考CRS以及描述边界维度的值组成。如:46,102,47,103,urn:ogc:def:crs:EPSG:6.6:4326,2

响应数据格式的数据结构

ResponseForm data structure
namedescriptionData typemultiplicity
Response Document指示输出应作为WPS响应文档的一部分返回。Zero or one
RawData Output指示输出应直接作为原始数据返回,不应有WPS响应文档Zero or one
ResponseDocument data structure
namedescriptiondatatypeMultiplicity
storeExecuteResponse指示execute请求的响应结果是否存储booleanZero or one
lineage指示Execute操作的响应结果是否包含DataInputs和OutputDefinitions元素booleanZero or one
status指示是否更新Process流程的状态booleanZero or one
Output指定响应结果的格式、编码和schema约束One or more

示例:

<wps:ResponseForm>
    <wps:ResponseDocument lineage="true" storeExecuteResponse="true" status="true">
        <wps:Output asReference="false">
            <ows:Identifier>result</ows:Identifier>
        </wps:Output>
    </wps:ResponseDocument>
</wps:ResponseForm>

asReference属性指定该输出是否应被Process进程存储为Web可访问的资源。

RawDataOutput data structure
namedescriptiondatatypeMultiplicity
Identifier指示输出结果的参数One
mimeType响应结果类型字符串Zero or one
encoding响应结果的编码uriZero or one
schemaRawDataOutput结果的约束uriZero or one
uom单位uriZero or one

示例:

<wps:ResponseForm>
    <wps:RawDataOutput mimeType="application/gml-3.1.1">
        <ows:Identifier>result</ows:Identifier>
    </wps:RawDataOutput>
</wps:ResponseForm>

Execute操作的请求方式

  • KVP键值对,get请求。
  • XML文本,post请求。

Execute 操作的URL请求参数:

nameOptionality and usedescription
service=WPSm服务类型标识
request=Executem操作名称
version=1.0.0m操作版本
language=en-CAo
Identifier=JST:buffermProcess标识
DataInputso
ResponseDocumento
RawDataOutputo
storeExecuteResponse=trueo
lineage=trueo
status=trueo

KVP请求方式中DataInputs 、ResponseDocument 和 RawDataOutput 参数的语法:

DataInputs := Input *( “;” Input )

Input := BoundingBox | Literal | Complex | Reference

DataInputs的值是零个或多个Input类型(BoundingBox、Literal、Complex、Reference),多个Input之间使用;隔开

BoundingBox := InputId “=” BoundingBoxValue

BoundingBoxValue := <As defined in OGC # 06-121r3 Subclause 10.2.3>

使用=分隔,输入参数和其值,以及分隔参数值的属性和属性值。

例如:bboxInput=46,102,47,103,urn:ogc:def:crs:EPSG:6.6:4326,2

Literal := InputId “=” Value *( “@” LiteralAttribute )

LiteralAttribute := LiteralAttributeName “=” Value

LiteralAttributeName := “datatype” | “uom”

使用@符号将输入值中的多个属性分隔开

例如:width=35@datatype=xs:integer@uom=meter

Complex := InputId “=” Value *( “@” ComplexAttribute )

ComplexAttribute:= ComplexAttributeName “=” Value

ComplexAttributeName := “mimetype” | “encoding” | “schema”

Reference := InputId “=” Value *( “@” ReferenceAttribute )

ReferenceAttribute:= ReferenceAttributeName “=” Value

ReferenceAttributeName := “href” | ComplexAttributeName

InputId := <Identifier of the input from the process description>

Value := <URL Encoded value being sent>

注意:字段名和属性名区分大小写。不正确的字段名和属性名将引发InvalidParameterException

示例:

KVP请求方式

http://localhost:8080/geoserver/ows?service=wps&request=execute&version=1.0.0&Identifier=JTS:buffer&DataInputs=geom=POINT(0 0)@mimeType="application/wkt";distance=10@datatype=xs:integer@uom=meter;quadrantSegments=2;capStyle=Round&RawDataOutput=result

image-20210513104832309

XML文本的方式

请求地址:http://localhost:8080/geoserver/wps 或 http://localhost:8080/geoserver/ows

body:

<?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:buffer</ows:Identifier>
  <wps:DataInputs>
    <wps:Input>
      <ows:Identifier>geom</ows:Identifier>
      <wps:Data>
        <wps:ComplexData mimeType="application/wkt"><![CDATA[POINT(0 0)]]></wps:ComplexData>
      </wps:Data>
    </wps:Input>
    <wps:Input>
      <ows:Identifier>distance</ows:Identifier>
      <wps:Data>
        <wps:LiteralData>10</wps:LiteralData>
      </wps:Data>
    </wps:Input>
    <wps:Input>
      <ows:Identifier>quadrantSegments</ows:Identifier>
      <wps:Data>
        <wps:LiteralData>2</wps:LiteralData>
      </wps:Data>
    </wps:Input>
    <wps:Input>
      <ows:Identifier>capStyle</ows:Identifier>
      <wps:Data>
        <wps:LiteralData>Round</wps:LiteralData>
      </wps:Data>
    </wps:Input>
  </wps:DataInputs>
  <wps:ResponseForm>
    <wps:RawDataOutput mimeType="application/wkt">
      <ows:Identifier>result</ows:Identifier>
    </wps:RawDataOutput>
  </wps:ResponseForm>
</wps:Execute>

<![CDATA[]]>标签所包含的内容将表示为纯文本,用来包含不被xml解析器解析的内容。

JTS:buffer的WPS服务描述中可以看到,默认的输出格式是gml/3.1.1。使用KVP方式请求的时候将RawDataOutput设置为result=geometry@mimeType="application/wkt"结果并没有效果;但在使用XML方式请求时,设置RawDataOutput标签中的mimeType属性才有效。所以遗留一个问题:如何在KVP的请求方式中设置WPS服务结果的输出格式呢?

虽然XML文本使用上看起来比较复杂,对于一些复杂的请求,使用XML文本通常更安全和高效。而kvp方式,特别是wps的execute请求可能会很棘手,并导致不可预测的错误。

什么?WPS服务的XML文本请求不会写?没关系,可以不用写,直接使用GeoServer中的WPS request builder演示工具生成,看得懂就行。

image-20210513115418188

3. WPS状态

当我们发送Execute操作的请求中没有携带RawDataOutput参数时,请求默认响应的是ExecuteResponseXML文档,里面包含了Process流程执行状态和响应结果。

3938

在首页中的Process status可以查看服务器中所有执行的execute操作的列表:

image-20210513172051814

image-20210513172158869

4. GeoServer提供的Process

Web Processing Service描述了发布地理处理Process流程的方法,但没有指定这些Process流程应该是什么。因此,实现WPS的服务器在实现什么类型的流程以及如何实现这些流程方面有完全的灵活性。

GeoServer根据主题将过程分为几个不同的类别。这些类别按前缀分组:

  • geo: geometry processes
  • ras: raster processes
  • vec: Vector processes
  • gs: GeoServer-specific processes

GeoServer以前的版本不是按主题,而是按负责实现的内部库对进程进行分组。JTSgt前缀可以被启用以保持向后兼容性,它们的功能被存储到vecgeo中了。

4.1 geometry processes

geometry processes使用的是JTS Topology Suite构建的,用于处理二维几何拓扑关系的Process。

JTS符合OGC的Simple Features Specification for SQL规范,类似于PostGIS。JTS包括常见的空间功能,如区域、缓冲区、交叉点和简化。

geo:area
geo:boundary
geo:buffer
geo:centroid
geo:contains
geo:convexHull
geo:crosses
geo:densify
geo:difference
geo:dimension
geo:disjoint
geo:distance
geo:endPoint
geo:envelope
geo:equalsExact
geo:equalsExactTolerance
geo:exteriorRing
geo:geometryType
geo:getGeometryN
geo:getX
geo:getY
geo:interiorPoint
geo:interiorRingN
geo:intersection
geo:intersects
geo:isClosed
geo:isEmpty
geo:isRing
geo:isSimple
geo:isValid
geo:isWithinDistance
geo:length
geo:numGeometries
geo:numInteriorRing
geo:numPoints
geo:overlaps
geo:pointN
geo:polygonize
geo:relate
geo:relatePattern
geo:reproject
geo:simplify
geo:splitPolygon
geo:startPoint
geo:symDifference
geo:touches
geo:union
geo:within

4.2 geoserver processes

GeoServer中的WPS包含一些专门为GeoServer创建的Process流程。这些通常是特定于geoserver的函数,比如边界和重投影。它们使用到GeoServer WFS/WCS的内部连接来读写数据,而不是WPS规范的一部分。

gs:AddCoverages
gs:Aggregate
gs:AreaGrid
gs:BarnesSurface
gs:Bounds
gs:BufferFeatureCollection
gs:Centroid
gs:Clip
gs:CollectGeometries
gs:Contour
gs:Count
gs:CropCoverage
gs:Feature
gs:GeorectifyCoverage
gs:GetFullCoverage
gs:Grid
gs:Heatmap
gs:Import
gs:InclusionFeatureCollection
gs:IntersectionFeatureCollection
gs:LRSGeocode
gs:LRSMeasure
gs:LRSSegment
gs:MultiplyCoverages
gs:Nearest
gs:PagedUnique
gs:PointBuffers
gs:PointStacker
gs:PolygonExtraction
gs:Query
gs:RangeLookup
gs:RasterAsPointCollection
gs:RasterZonalStatistics
gs:RectangularClip
gs:Reproject
gs:ReprojectGeometry
gs:ScaleCoverage
gs:Simplify
gs:Snap
gs:StoreCoverage
gs:StyleCoverage
gs:Transform
gs:UnionFeatureCollection
gs:Unique
gs:VectorZonalStatistics
gt:VectorToRaster

官网在这段介绍了gs:Aggregate聚合函数:计算要素属性上的一个或多个聚合函数,包括Count, Average, Max, Median, Min, StdDev, Sum。

ParameterDescriptionMandatoryMultiple
features输入要素的集合yesno
aggregationAttribute用于聚合计算的属性yesno
function具体的聚合操作,可选值: Count, Average, Max, Median, Min, StdDev, Sum.yesyes
singlePass如果为true,则在一次传递中计算所有聚合值。这将阻碍特定于dbms的优化。如果提供了group by属性,则将忽略此参数。yesno
groupByAttributes分组属性noyes
image-20210514101311590

响应结果:

{
    "GroupByAttributes":["SUB_REGION"],
    "AggregationResults":[
        [
            "N Eng",2201157.1666666665
        ],
        [
            "W N Cen",2522812.8571428573
        ],
        [
            "Pacific","1.2489678E7"
        ],
        [
            "Mtn",1690408.25
        ],
        [
            "E S Cen",3998821.25
        ],
        [
            "S Atl",4837695.666666667
        ],
        [
            "E N Cen",8209477.2
        ],
        [
            "Mid Atl","1.2534095333333334E7"
        ],
        [
            "W S Cen",6709575.75
        ]
    ],
    "AggregationFunctions":["Average"],
    "AggregationAttribute":"PERSONS"
}

5. Process chaining

从上面GeoServer提供的Process中可以看出,这些Process流程更多的是单一的几何服务,类似ArcGIS Server中的geometry service或ArcMap中的工具箱。虽然GeoServer中没有像ArcGIS中的model builder 那样niubility的可视化建模工具,但还是可以将多个Process流程组合实现空间建模分析的。

其实如果不是比较复杂的需求可以直接通过空间数据库中的空间函数解决,如PostGIS。

WPS服务的好处之一是其固有的链接流程的能力。就像函数如何调用其他函数一样,WPS进程可以将另一个进程的输出用作其输入。因此,许多复杂的功能可以组合成一个强大的请求。

例如,让我们采用GeoServer随附的一些示例数据,并使用WPS引擎链接一些内置过程,这将允许用户即时执行地理空间分析。

示例:保护区内的道路一共有几英里?

GeoServer的标准安装中包含了用于此示例的数据:

  • sf:roads:包含道路信息的图层
  • sf:restricted:代表保护区的图层
image-20210514115237451

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

  • gs:IntersectionFeatureCollection:返回两个要素集合之间的交集,并添加两个要素集合的属性
  • gs:CollectGeometries:收集要素集中的所有默认几何并将其作为单个几何集合返回
  • JTS:length:以与几何相同的度量单位计算几何的长度

这些过程的执行顺序很重要。我们先求道路网络与保护区Intersection相交,获得保护区内所有道路的要素集合。然后,我们将这些几何形状收集到单个GeometryCollection中,以便可以使用内置的JTS算法来计算长度。

image-20210514151345172

Process流程的顺序是通过将第一个process嵌入到第二个process,再将第二个process嵌入到第三个process,…这种方式来构建整个Process流程的WPS请求。

工作流:一个process流程产生一些输出,这些输出将成为下一个process流程的输入,从而形成一个处理管道,可以通过一个HTTP请求解决复杂的空间分析。这里最开始的输入使用GeoServer的图层layer,优势在于不会在process流程之间来回传送数据,从而获得非常好的性能。

完整的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>

image-20210514152335032

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: Geoserver是一款用于发布地理信息数据的开源软件,可以方便地将存储在PostGIS、Oracle、MySQL等关系数据库的矢量和栅格数据发布为Web服务。以下是关于Geoserver文教程的相关内容。 Geoserver官方网站提供了完整的英文文档,但是对于普通用户来说,这可能会带来艰难的理解和操作挑战。因此,一些Geoserver文教程在互联网上涌现。 例如,有一些博客和论坛上提供了一系列基础和高级的Geoserver教程。这些教程内容涵盖了Geoserver的安装与配置、数据导入、样式设计和高级功能等方面。这些教程包含了许多图文并茂的步骤,使得读者可以更容易地学习和应用Geoserver。 此外,还有一些在线课程和视频教程可以帮助用户更好地理解和使用Geoserver。这些教程通常包括对Geoserver和WebGIS的介绍、Geoserver的基础与高级功能,以及如何使用Geoserver发布地理图层等方面的内容。 Geoserver文教程的不足之处在于它们往往是分散的,没有集的官方教程资料,不便于查找和使用。此外,由于Geoserver自身不断更新升级,一些教程可能已经过时,需要特别注意和确认。因此,建议用户在使用Geoserver时,仔细阅读官方文档并结合实际情况。 ### 回答2: Geoserver是一个开源的地理信息系统服务器软件,它提供了 Web服务接口,允许用户动态地将空间数据以地图形式呈现在 Web页面上。Geoserver是基于Java开发的,它能够处理和发布各种地理数据,包括矢量数据、栅格数据、数据库数据等,并支持OGC标准,比如WMS、WFS、WCS、SLD等,提供了各种控制地图样式、标注、符号、图层控制、分层显示等功能。 Geoserver文教程,可以通过官方文档和社区的帮助文档来学习和了解。官方文档提供了详尽的入门指南、安装教程、高级主题等内容,同时还包括 API 参考、样式编辑器等工具的使用说明。社区还提供了丰富的教学视频和论坛帮助,用户可以在其了解最新的开源工具、掌握使用技巧、分享经验和解决问题。 其,对于初学者来说,建议按照以下步骤学习 Geoserver: 1. 下载 Geoserver,安装和启动 Geoserver,并访问其 Web页面和管理界面。 2. 学习 Geoserver 对于数据的支持,包括数据类型、格式和存储等,以及如何创建和发布数据。 3. 了解 Geoserver 支持的OGC标准和Web服务,并学习如何创建和配置 WMS、WFS、WCS等服务。 4. 掌握样式编辑器的使用和相关符号和标注的设置,以及图层控制和分层显示的实现方法。 5. 通过学习 Geoserver 的高级特性,如集群部署、扩展和优化等,以更好地实现你的 GIS应用。 总之,Geoserver 文教程提供了全面的学习资料,可以让用户快速掌握地理信息系统服务器的使用方法和技巧,开发高效的WebGIS应用,同时还可以为 Geoserver社区做出贡献。 ### 回答3: Geoserver是一个强大的开源地理信息系统服务器,可以轻松地发布地理数据和地图服务Geoserver文教程可以帮助初学者更好地了解和利用Geoserver,快速入门,以便最大程度地利用Geoserver的优点。 Geoserver文教程包含了从安装到使用的全面内容,包括Geoserver的基本概念、数据源的配置、发布地图服务、使用WPS等。在这些教程,不仅会涵盖基础知识,还会介绍Geoserver高级应用的一些技巧和常见问题的解决方法。 同时,Geoserver文教程也提供了大量的代码和实例,以便读者更好地理解和学习。这些实例和代码可以用于展示地图、发布地图服务,还可以作为学习Geoserver的实践材料。 总之,Geoserver文教程可以帮助初学者快速获得对该软件的了解和掌握,也可以帮助专业人员进行更加高级和复杂的应用。Geoserver文教程的编写对于推进地理信息系统的发展和应用,也有着积极的促进作用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值