../../_images/logo_pygeoapi.png ../../_images/OSGeo_project.png

pygeoapiクイックスタート

pygeoapiは、OGC Open APIサービスをWeb上で迅速かつ容易に公開するためのツールです。(geo)pythonコミュニティの強力なオープンソースライブラリ上に構築されています。

このクイックスタートでは、ソフトウェアのセットアップ方法を説明し、特定ケースを想定して使用してみます。pygeoapiはビジネス、ビジネスケースを満たすために他のコンポーネントと組み合わされる製品なので、説明の途中で関連するソフトウェアをいくつか取り上げます。

前提知識

pygeoapiは空間ドメイン用のPython Webアプリケーションであるため、Webアプリケーションの概念と、グリッドおよびベクタフォーマット、OGC標準、投影システムなどの空間処理的側面を意識する必要があります。Pythonの知識が推奨されますが、OSGeoLiveからアプリケーションを実行しなくてもかまいません。

設定とサービスの開始

  1. スタートメニューから Structure ‣ osgeolive ‣ appmenupath ‣ pygeoapi を選択します。Webページ http://localhost:5000 でアプリケーションを開きます。

  2. ユーザフォルダの /usr/local/share/pygeoapi へ行きファイル pygeoapi-config.yml を配置します。このファイルには、サービスの構成が含まれています。

  3. コマンド sudo nano pygeoapi-config.yml でファイルを開きます。

  4. Title や Author など、ファイル内の一部のパラメータを更新します。ファイルを保存します。

  5. 端末を閉じてサービスを起動し直すなどして、サービスを再開します。

    ../../_images/pygeoapi_screenshot.png

新しいサービスの構成

ここでは、ベクタ・データセットをpygeoapiにデプロイし、その機能をOGC API-Featuresとして公開します。OGC API - Fearures は、ベクタ機能をWebサービスとして公開するためのOGCの標準です。OGC API - Featuresは、WFSの代替となる OpenAPI機能です。

pygeoapiは、geopackage、PostGIS、Elasticsearch、WFSなど、ベクタソースとして使用する幅広いバックエンドをサポートしています。GDAL OGR プロバイダを経由して、ほぼ無制限に、他のベクタソース一式が追加できます。

Interesting datasets to expose as OGC API - Features consist of real world data having multiple attributes and links to other resources. OSGeoLive contains a number of datasets we can use. An example is /var/www/html/openlayers/examples/data/geojson/countries.geojson. You can configure it in pygeoapi using the GeoJSON provider.

  1. GeoJSONファイルをダウンロードし、tests/data フォルダーに配置します。

  2. Update pygeoapi-config.yml to add countries as a new collection to pygeoapi (insert snippet below between the other collections. Mind the nesting, nesting is important in YAML syntax).

countries:
   type: collection
   title: Countries
   description: Countries of the world
   keywords:
      - industry
   links:
      - type: text/html
        rel: canonical
        title: information
        href: https://openlayers.org
        hreflang: en-US
   extents:
      spatial:
         bbox: [-180,-90,180,90]
   providers:
      - type: feature
        name: GeoJSON
        data: /var/www/html/openlayers/examples/data/geojson/countries.geojson
        id_field: name
  1. pygeoapiの再起動

ブラウザで http://localhost:5000/collections/countries を開いて、コレクションの検証をおこなう

Webブラウザを使用したAPIのクエリー

Now that we have the service available we can query it using various client tooling. Each of the features of the collection is available in common formats, such as HTML, GeoJSON and GML. To start we can use a web browser to browse through the service. From http://localhost:5000/collections/countries, drill down to individual features. The service will automatically detect (accept header) that you are using a web browser and will return the HTML representation of features. Notice in the top right corner explicit links to override the accept header and request specific representations of the feature (?f=json).

各Open APIには、http://localhost:5000/openapi にインタラクティブなドキュメントページがあります。このインタラクティブなWebページでは、サービス内のさまざまなメソッドについて読むことができますが、Webフォームを介してそれらのメソッドと直接対話することもできます。

../../_images/openapidoc.png

OGC API’s have been developed with the W3C Spatial Data on the Web Best Practices in mind. An important aspect of these best practices is search engine optimization. Pygeoapi adds some crawl optimizations on top of the requirements of the Open API standards; collection metadata can be crawled by search engines in a structured way, with the goal to make the collections discoverable in tools like Google Dataset Search. To evaluate the structured data capabilities you can use the Structured Data Testing tools of Yandex or Google. Copy the html source of the countries collection page (or the url of a collection page of an online pygeoapi instance) into a structured data testing tool and evaluate what structured data the tool is able to extract from it. The search engine will use that information in its datasets index.

Using OGC API - Features in Desktop GIS

このクイックスタートでは、QGISを用いてサービスのクエリを行ないますが、例えば ArcGIS, FME, OpenLayers といった他のツールでも、類似のワークフローを実施できます。

Starting from QGIS 3.14 you can add an OGC API - Features layer as vector layer. From the Layer / Add Layer menu select Add WFS Layer....

../../_images/qgis-wfs.png

新しい接続を作成するウィンドウが開いたら、サービスのURL http://localhost:5000 を入力します。

OKをクリックして、サービスで使えるコレクションをロードするため connect します。

../../_images/qgis-layers.png

countries コレクションを選択して、 ‘Add’ をクリックしてQGISマップにレイヤを追加します。