zoukankan      html  css  js  c++  java
  • 标准WPS框架下的空间信息处理服务部署方法

    笔者第一篇博客里面曾介绍过将专题图制作功能发布为WPS,但随着后面的研究,才发现那时候发布的不是真正WPS框架下的服务,而只是通过Servlet将其发布为可调用的网络服务,所以今天再具体介绍一下真正的WPS服务到底如何发布。

    WPS(Web Processing Service)是OGC组织制定的空间信息处理服务的标准规范,旨在以标准化的方式在网络上共享空间信息处理功能。WPS主要用来处理空间数据,实现通过网络向客户端提供地理数据的处理服务,使客户无需安装桌面软件就能实现相关的处理功能。它定义一个标准的接口来帮助实现地理进程发布和绑定进程与客户端,“进程”包括任何能够操作空间数据的算法、计算或模型,“发布”意思是提供机器可读的绑定信息和人们可读的元数据信息以便服务的发现和使用。一个WPS可以被配置提供任何功能的GIS空间数据处理功能,将WPS进程链接在一起能够生成可以复用的工作流。

    在WPS中,客户端和服务器采用基于XML的通信方式,在WPS接口中定义了三个主要操作,用于向客户端提供服务详细信息、查询部署在服务器上的进程描述和执行进程,这三个主要操作分别是:GetCapabilities、DescribeProcess和Execute。GetCapabilities操作允许客户端从服务器中检索元数据,使客户端通过请求获得描述具体信息的元数据文档,该文档包括所有可执行的进程简要的元数据信息描述。DescribeProcess操作使客户通过请求获得进程的详细信息,包括输入、输出参数和格式等。Execute操作允许WPS客户端提供输入参数值,然后在服务器端运行指定的进程,并返回输出结果。

    下面介绍将算子模型部署到WPS框架的具体步骤:

    一、获取WPS工程

    我使用的工程来自师门提供,不能外传,可以从网上找到开源的相关代码,其目录结构如下所示:

    二、部署需要调用的Java类

    将算法调用java文件放到cn.edu.whu.lmars.reflect.services路径下,将文件名和类名更改统一,比如此处改为DzLdksmnProcess.java,添加对接口IReflectService的实现,如下语句所示:

    public class DzLdksmnProcess extends Model implements IReflectService

    添加接口方法的实现函数:

    public Object execute(HashMap<Object, Object> layers, HashMap<Object, Object> paramters)

    建议先完成四、五两个步骤之后再实现这个接口,最终实现后的函数内容如下:

     1 @Override
     2 public Object execute(HashMap<Object, Object> layers, HashMap<Object, Object> paramters) {
     3     // TODO Auto-generated method stub
     4     String firstInput = "QuHuaShp";
     5     String secondInput = "LieDuShp";
     6     String input1_href = layers.get(firstInput + IReflectService.DATAHREF).toString();
     7     String input2_href = layers.get(secondInput + IReflectService.DATAHREF).toString();
     8     String output = layers.get(IReflectService.OUTPUTNAME).toString();
     9         
    10     File file = new File(output);
    11     if(file.exists()){
    12             file.delete();
    13     }        
    14     try {
    15         DzLdksmnProcess.mainprocess(input1_href, input2_href, output);
    16     } catch (Exception e) {
    17         e.printStackTrace();
    18     }        
    19     return true;
    20 }

    三、在jni目录下添加编译文件

    如果有需要调用的其他文件,比如.exe、.dll、.py、.so等文件,要将其放到wps10/WebContent/jni目录下,并添加相应的引用。

    此例子中需要将arcobjects.jar添加到Referenced Libraries,jar包文件放于wps10/WebContent/WEB-INF/lib目录下,并将其添加到Build Path。

    四、添加ProcessDescription的xml文档

    创建DzLdksmnProcess类的ProcessDescription XML文档,注意其中的Identifier属性要和类名一样,内容编辑完成后将其放到wps10/ WebContent/config/processes路径下。

    DzLdksmnProcess.xml内容如下:

      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <wps:ProcessDescriptions xmlns:wps="http://www.opengis.net/wps/1.0.0" 
      3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      4     xmlns:ows="http://www.opengis.net/ows/1.1" 
      5     xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd" 
      6     xml:lang="en-US" service="WPS" version="1.0.0">
      7 <ProcessDescription statusSupported="true" storeSupported="true" wps:processVersion="1.1.0">
      8     <ows:Identifier>DzLdksmnProcess</ows:Identifier>
      9     <ows:Title>地震烈度模型</ows:Title>
     10     <ows:Abstract>利用地震震级、震中地理坐标和震源机制解等相关参数绘制地震烈度图</ows:Abstract>
     11     <DataInputs>
     12     <Input minOccurs="1" maxOccurs="1">
     13         <ows:Identifier>QuHuaShp</ows:Identifier>
     14         <ows:Title>行政区划图</ows:Title>
     15         <ComplexData>
     16             <Default>
     17                 <Format>
     18                 <MimeType>application/x-zipped-shp</MimeType>
     19                 </Format>
     20             </Default>
     21             <Supported>
     22                 <Format>
     23                     <MimeType>application/x-zipped-shp</MimeType>
     24                 </Format>
     25                 <Format>
     26                     <MimeType>text/xml; subtype=gml</MimeType>
     27                 </Format>
     28                 <Format>
     29                     <MimeType>text/xml; subtype=gml/2.0.0</MimeType>
     30                 </Format>
     31                 <Format>
     32                     <MimeType>text/xml; subtype=gml/2.1.1</MimeType>
     33                 </Format>
     34                 <Format>
     35                     <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
     36                 </Format>
     37                 <Format>
     38                     <MimeType>text/xml; subtype=gml/2.1.2.1</MimeType>
     39                 </Format>
     40                 <Format>
     41                     <MimeType>text/xml; subtype=gml/3.0.0</MimeType>
     42                 </Format>
     43                 <Format>
     44                     <MimeType>text/xml; subtype=gml/3.0.1</MimeType>
     45                 </Format>
     46                 <Format>
     47                     <MimeType>text/xml; subtype=gml/3.1.0</MimeType>
     48                 </Format>
     49                 <Format>
     50                     <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
     51                 </Format>
     52                 <Format>
     53                     <MimeType>text/xml; subtype=gml/3.2.1</MimeType>
     54                 </Format>
     55             </Supported>
     56         </ComplexData>
     57     </Input>
     58     <Input minOccurs="1" maxOccurs="1">
     59         <ows:Identifier>LieDuShp</ows:Identifier>
     60         <ows:Title>断裂带分布图</ows:Title>
     61         <ComplexData>
     62             <Default>
     63                 <Format>
     64                 <MimeType>application/x-zipped-shp</MimeType>
     65                 </Format>
     66             </Default>
     67             <Supported>
     68                 <Format>
     69                     <MimeType>application/x-zipped-shp</MimeType>
     70                 </Format>
     71                 <Format>
     72                     <MimeType>text/xml; subtype=gml</MimeType>
     73                 </Format>
     74                 <Format>
     75                     <MimeType>text/xml; subtype=gml/2.0.0</MimeType>
     76                 </Format>
     77                 <Format>
     78                     <MimeType>text/xml; subtype=gml/2.1.1</MimeType>
     79                 </Format>
     80                 <Format>
     81                     <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
     82                 </Format>
     83                 <Format>
     84                     <MimeType>text/xml; subtype=gml/2.1.2.1</MimeType>
     85                 </Format>
     86                 <Format>
     87                     <MimeType>text/xml; subtype=gml/3.0.0</MimeType>
     88                 </Format>
     89                 <Format>
     90                     <MimeType>text/xml; subtype=gml/3.0.1</MimeType>
     91                 </Format>
     92                 <Format>
     93                     <MimeType>text/xml; subtype=gml/3.1.0</MimeType>
     94                 </Format>
     95                 <Format>
     96                     <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
     97                 </Format>
     98                 <Format>
     99                     <MimeType>text/xml; subtype=gml/3.2.1</MimeType>
    100                 </Format>
    101             </Supported>
    102         </ComplexData>
    103     </Input>
    104     </DataInputs>
    105     <ProcessOutputs>
    106     <Output>
    107         <ows:Identifier>OutputData</ows:Identifier>
    108         <ows:Title>地震烈度图</ows:Title>
    109         <ComplexOutput>
    110             <Default>
    111                 <Format>
    112                 <MimeType>application/x-zipped-shp</MimeType>
    113                 </Format>
    114             </Default>
    115             <Supported>
    116                 <Format>
    117                     <MimeType>application/x-zipped-shp</MimeType>
    118                 </Format>
    119                 <Format>
    120                     <MimeType>text/xml; subtype=gml</MimeType>
    121                 </Format>
    122                 <Format>
    123                     <MimeType>text/xml; subtype=gml/2.0.0</MimeType>
    124                 </Format>
    125                 <Format>
    126                     <MimeType>text/xml; subtype=gml/2.1.1</MimeType>
    127                 </Format>
    128                 <Format>
    129                     <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
    130                 </Format>
    131                 <Format>
    132                     <MimeType>text/xml; subtype=gml/2.1.2.1</MimeType>
    133                 </Format>
    134                 <Format>
    135                     <MimeType>text/xml; subtype=gml/3.0.0</MimeType>
    136                 </Format>
    137                 <Format>
    138                     <MimeType>text/xml; subtype=gml/3.0.1</MimeType>
    139                 </Format>
    140                 <Format>
    141                     <MimeType>text/xml; subtype=gml/3.1.0</MimeType>
    142                 </Format>
    143                 <Format>
    144                     <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
    145                 </Format>
    146                 <Format>
    147                     <MimeType>text/xml; subtype=gml/3.2.1</MimeType>
    148                 </Format>
    149             </Supported>
    150         </ComplexOutput>
    151     </Output>
    152     </ProcessOutputs>
    153 </ProcessDescription>
    154 </wps:ProcessDescriptions>

    五、添加Execute的xml文档

    创建DzLdksmnProcess类的Execute XML文档,注意其中的Identifier属性要和类名一样,内容编辑完成后将其放到wps10/WebContent/requests2路径下。

    DzLdksmnProcess.xml内容如下:

     1 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     2 <wps:Execute service="WPS" version="1.0.0" xmlns:wps="http://www.opengis.net/wps/1.0.0" 
     3     xmlns:ows="http://www.opengis.net/ows/1.1" 
     4     xmlns:ogc="http://www.opengis.net/ogc" 
     5     xmlns:xlink="http://www.w3.org/1999/xlink" 
     6     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     7     xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_request.xsd">
     8     <ows:Identifier>DzLdksmnProcess</ows:Identifier>
     9     <ows:Title>地震烈度模型</ows:Title>
    10     <ows:Abstract>利用地震震级、震中地理坐标和震源机制解等相关参数绘制地震烈度图</ows:Abstract>
    11     <wps:DataInputs>
    12     <wps:Input>
    13         <ows:Identifier>QuHuaShp</ows:Identifier>
    14         <ows:Title>行政区划图</ows:Title>
    15         <wps:Reference mimeType="application/x-zipped-shp" 
    16             xlink:href="http://localhost:8080/wps10/datas/shapefile/china.zip" method="GET"/>
    17     </wps:Input>
    18     <wps:Input>
    19         <ows:Identifier>LieDuShp</ows:Identifier>
    20         <ows:Title>断裂带分布图</ows:Title>
    21         <wps:Reference mimeType="application/x-zipped-shp" 
    22             xlink:href="http://localhost:8080/wps10/datas/shapefile/Duanceng.zip" method="GET"/>
    23     </wps:Input>
    24     </wps:DataInputs>
    25     <wps:ResponseForm>
    26     <wps:ResponseDocument storeExecuteResponse="false" lineage="false" status="false">
    27       <wps:Output asReference="true" mimeType="application/x-zipped-shp" encoding="UTF-8">
    28         <ows:Identifier>OutputData</ows:Identifier>
    29         <ows:Title>地震烈度图</ows:Title>
    30       </wps:Output>
    31     </wps:ResponseDocument>
    32     </wps:ResponseForm>
    33 </wps:Execute>

    六、在common_algorithms.properties下添加键值对

    打开wps10/WebContent/config路径下的

    common_algorithms.properties文件,在最后一行下面添加:

    DzLdksmnProcess=cn.edu.whu.lmars.reflect.ReflectAlgorithm

    (注意key要和类名一样)

    七、在index.html添加执行页面

    打开wps10/WebContent路径下的index.html文件,找到

    var requests = new Array();并在下面添加新的指定值:

    requests[159] = datafolder + "DzLdksmnProcess.xml";

    (注意这里是添加第五步的Execute xml文档)

    八、测试

    至此,所有部署工作已经完成,将整个工程用tomcat发布,本地的访问页面如下所示:

    可以成功访问即可。

  • 相关阅读:
    git config 命令各参数有何区别
    Git 初始化
    Linux 安装 Git
    在Mac OS 上安装 Git
    maven 部署到远程仓库(私服)
    Git与SVN的区别
    windows挂载NFS文件系统无法访问/修改文件解决
    mysql5.7写入数据时间相差13/14小时解决
    mysql配置文件不生效解决
    springdata jpa mysql5.7写入中文乱码解决
  • 原文地址:https://www.cnblogs.com/MatthewHome/p/10910888.html
Copyright © 2011-2022 走看看