Changes between Version 1 and Version 2 of ZooWorkshop/FOSS4GJapan/ja/CreatingOGRBasedWebServices


Ignore:
Timestamp:
Oct 27, 2010, 2:32:17 PM (13 years ago)
Author:
hayashi
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ZooWorkshop/FOSS4GJapan/ja/CreatingOGRBasedWebServices

    v1 v2  
    77
    88
     9
    910== Introduction ==
    1011翻訳中・・・
     12
     13== Preparing ZOO metadata file ==
     14翻訳中・・・
     15
     16=== Boundary ===
     17翻訳中・・・
     18
     19==== C Version ====
     20翻訳中・・・
     21
     22==== Python Version ====
     23翻訳中・・・
     24
     25==== Testing the Service using Execute Request ====
     26翻訳中・・・
     27
     28===== The simple and unreadable way =====
     29翻訳中・・・
     30
     31===== Simplification and readability of request =====
     32翻訳中・・・
     33
     34=== Creating Services for other functions (!ConvexHull and Centroid) ===
     35翻訳中・・・
     36
     37==== C Version ====
     38翻訳中・・・
     39
     40==== Python Version ====
     41翻訳中・・・
     42
     43=== バッファサービス作成 ===
     44
     45我々はバッファサービスを使用することができますが、他のサービスに比べ多くの引数を取得可能です。実際コードは、境界や凸包、そして中心点生成サービスを実装する際に使用されるものと少々異なっているからです。
     46
     47バッファサービスは、ジオメトリを入力したものを取得しますが、使用するのは {{{BufferDistance}}のパラメータです。これにより、{{{BufferDistance}}が単純な整数値になるので、 {{{LitteralData}}}ブロックを定義できるでしょう。そのような種類の入力値を読み込んでアクセスすると、以前使用したのと同じ機能が使用されます。
     48
     49==== C バージョン ====
     50
     51あなたが、最初の境界サービスのソースコードへ戻るならば、以下について非常に複雑になることに気づくべきではありません。実際、あなたはBufferDistanceのアクセスに加えて、ラインを変更する際に[http://www.gdal.org/ogr/ogr__api_8h.html#1ca0bd5c0fcb4b1af3c3973e467b0ec0 OGR_G_Buffer]が( {{{OGR_G_GetBoundary}}}の代わりに)呼び出されるべきだからです。ここに、全てのlcodeを示します:
     52
     53{{{
     54int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
     55  OGRGeometryH geometry,res;
     56  map* tmp1=getMapFromMaps(inputs,"InputPolygon","value");
     57  if(tmp==NULL){
     58    setMapInMaps(conf,"lenv","message","Unable to fetch InputPolygon value.");
     59    return SERVICE_FAILED;
     60  }
     61  map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
     62  if(strncmp(tmp->value,"application/json",16)==0)
     63    geometry=OGR_G_CreateGeometryFromJson(tmp->value);
     64  else
     65    geometry=createGeometryFromWFS(conf,tmp->value);
     66  double bufferDistance=1;
     67  tmp=getMapFromMaps(inputs,"BufferDistance","value");
     68  if(tmp!=NULL)
     69    bufferDistance=atof(tmp->value);
     70  res=OGR_G_Buffer(geometry,bufferDistance,30);
     71  tmp1=getMapFromMaps(outputs,"Result","mimeType");
     72  if(strncmp(tmp1->value,"application/json",16)==0){
     73    char *tmp=OGR_G_ExportToJson(res);
     74    setMapInMaps(outputs,"Result","value",tmp);
     75    setMapInMaps(outputs,"Result","mimeType","text/plain");
     76    free(tmp);   
     77  }
     78  else{
     79    char *tmp=OGR_G_ExportToGML(res);
     80    setMapInMaps(outputs,"Result","value",tmp);
     81    free(tmp);   
     82  }
     83  outputs->next=NULL;
     84  OGR_G_DestroyGeometry(geometry);
     85  OGR_G_DestroyGeometry(res);
     86  return SERVICE_SUCCEEDED;
     87}
     88}}}
     89
     90新しいコードは、あなたの{{{service.c}}} ファイルに挿入し、再コンパイルの後に{{{/usr/lib/cgi-bin/}}} ディレクトリにあるZOOサービスプロバイダーの旧バージョンと置き換わらなければなりません。あなたはもちろん、対応するZOOのメタデータファイルを同じディレクトリに置かなければなりません。
     91
     92以前の説明にあったように、ZOOカーネルは、zcfgファイルで定義されるよりも多くの引数を渡すことができます。なので、{{{Boundary.zcfg}}}ファイルを{{{Buffer.zcfg}}}と改名したコピーを使用して、バッファ識別子を記載してみましょう。その際、以前も行ったように {{{Execute}}} リクエストを用いてサービスをテストしてください。そうすると、{{{ResponseDocument}}}でバッファの結果を得られるでしょう。
     93
     94{{{BufferDistance}}}への入力がサービスをパスするならば、上のコードをチェックすることに注意したかもしれません。 もし、そうでなければデフォルト値として1を使用するようにして下さい。そうすると、なぜ前のクエリーにさらに入力する必要がないかがわかるからです。
     95
     96リクエストに!DataInputs値を加えることによって、ジオメトリのバッファを計算するのにあなたのサービスで使用された{{{BufferDistance}}} 値を変えることができます。KVPシンタックスを使用することで、各!DataInputsが、セミコロンによって分割されることに注意してください。
     97
     98以前のリクエスト:
     99
     100{{{
     101DataInputs=InputPolygon=Reference@xlink:href=http%3A%2F%2Flocalhost%3A8082%2Fgeoserver%2Fows%3FSERVICE%3DWFS%26REQUEST%3DGetFeature%26VERSION%3D1.0.0%26typename%3Dtopp%3Astates%26SRS%3DEPSG%3A4326%26FeatureID%3Dstates.15
     102}}}
     103
     104以下のように置き換えます:
     105
     106{{{
     107DataInputs=InputPolygon=Reference@xlink:href=http%3A%2F%2Flocalhost%3A8082%2Fgeoserver%2Fows%3FSERVICE%3DWFS%26REQUEST%3DGetFeature%26VERSION%3D1.0.0%26typename%3Dtopp%3Astates%26SRS%3DEPSG%3A4326%26FeatureID%3Dstates.15;BufferDistance=2
     108}}}
     109
     110{{{BufferDistance}}}値を2に設定する場合、異なる結果が与えられるでしょう。なぜなら、ソースコード上で1をデフォルト値と定めたため、いかなるパラメータも渡されないからです。
     111
     112ここで、 http://localhost/test_services.html のHTMLフォームから使用するXML形式における同じクエリを見つけられるでしょう:
     113
     114{{{
     115#!xml
     116<wps:Execute service="WPS" version="1.0.0" xmlns:wps="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" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 ../wpsExecute_request.xsda">
     117 <ows:Identifier>Buffer</ows:Identifier>
     118 <wps:DataInputs>
     119  <wps:Input>
     120   <ows:Identifier>InputPolygon</ows:Identifier>
     121   <ows:Title>Playground area</ows:Title>
     122   <wps:Reference xlink:href="http://localhost:8082/geoserver/ows/?SERVICE=WFS&amp;REQUEST=GetFeature&amp;VERSION=1.0.0&amp;typename=topp:states&amp;SRS=EPS
     123G:4326&amp;FeatureID=states.15"/>
     124  </wps:Input>
     125  <wps:Input>
     126   <ows:Identifier>BufferDistance</ows:Identifier>
     127   <wps:Data>
     128    <wps:LiteralData uom="degree">2</wps:LiteralData>
     129   </wps:Data>
     130  </wps:Input>
     131 </wps:DataInputs>
     132 <wps:ResponseForm>
     133  <wps:ResponseDocument>
     134   <wps:Output>
     135    <ows:Identifier>Buffer</ows:Identifier>
     136    <ows:Title>Area serviced by playground.</ows:Title>
     137    <ows:Abstract>Area within which most users of this playground will live.</ows:Abstract>
     138   </wps:Output>
     139  </wps:ResponseDocument>
     140 </wps:ResponseForm>
     141</wps:Execute>
     142}}}
     143
     144==== Python バージョン ====
     145
     146 すでにユーティリティ機能のcreateGeometryFromWFSとoutputResultを定義しているので、コードはこれと同じくらい簡単です:
     147
     148{{{
     149#!python
     150def Buffer(conf,inputs,outputs):
     151    geometry=extractInputs(inputs["InputPolygon"])
     152    try:
     153        bdist=int(inputs["BufferDistance"]["value"])
     154    except:
     155        bdist=10
     156    rgeom=geometry.Buffer(bdist)
     157    outputResult(outputs["Result"],rgeom)
     158    geometry.Destroy()
     159    rgeom.Destroy()
     160    return 3
     161}}}
     162
     163ここでは、["BufferDistance"]["value"]のインプットを、ジオメトリインスタンスにおけるバッファ方法を引数として加えたのみです。一旦このコードを、ogr_ws_service_provider.py ファイルに追加した後で、ZOOカーネルのディレクトリの中に(もしくは、ZOOサービスプロバイダのルートディレクトリからインストールする形で)それをコピーしてください。また、次のセクションでBuffer.zcfgファイルを詳述する必要があることに注意してください。
     164
     165==== バッファ !MetadataFile ファイル ====
     166
     167 クライアントにサービスがこのパラメータをサポートするようにするため、 サービス・メタデータ・ファイルに{{{BufferDistance}}}を加えなければなりません。 そうした上で、あなたのオリジナルのBoundary.zcfgファイルをBuffer.zcfgファイルとしてコピーして、!DataInputsのブロックに以下のラインを加えてください。
     168
     169{{{
     170[BufferDistance]
     171Title = Buffer Distance
     172Abstract = Distance to be used to calculate buffer.
     173minOccurs = 0
     174maxOccurs = 1
     175<LiteralData>
     176DataType = float
     177<Default>
     178uom = degree
     179value = 10
     180</Default>
     181<Supported>
     182uom = meter
     183</Supported>
     184</LiteralData>
     185}}}
     186
     187  {{{minOccurs}}}は、パラメータの入力が任意であることを意味するために0が設定されているので、パスを通す必要はありません。 むしろ、ZOOカーネルは、任意のパラメータのためにデフォルト設定値とサービス機能にデフォルト値を通すことを知る必要があります。
     188
     189あなたは、ここで {{{Buffer.zcfg}}}ファイルのフルコピーを取得できます。
     190
     191http://zoo-project.org/trac/browser/trunk/zoo-services/ogr/base-vect-ops/cgi-env/Buffer.zcfg
     192
     193あなたは、バッファサービスのために!GetCapabilitiesや !DescribeProcess そして Execute をZOOカーネルにたずねることが出来ます。
     194
     195[wiki:ZooWorkshop/FOSS4GJapan/ja/UsingZooFromOSGeoLiveVM Prev.] | [wiki:ZooWorkshop/FOSS4GJapan WorkShop table of content] | [wiki:ZooWorkshop/FOSS4GJapan/ja/BuildingWPSClientUsingOL Next]

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png