1. 程式人生 > >標準WPS框架下的空間資訊處理服務部署方法

標準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釋出,本地的訪問頁面如下所示:

可以成功訪問即