dayjournal memo

Total 975 articles!!

Try #092 – Amazon OpenSearch Serviceで空間検索してQGISで可視化してみた

Yasunori Kirimoto's avatar

img

img




Amazon OpenSearch Serviceで空間検索してQGISで可視化してみました!



詳細として下記について説明します。

  • 事前準備
  • ドメイン作成
  • OpenSearch Dashboardsに接続
  • 位置情報データ登録
  • 空間検索


事前準備

Amazon OpenSearch Serviceで利用するGISデータを準備します。今回は事前にQGISOpenStreetMapのサンプルデータを準備しました。


ポイントのGISデータをGeoJSONで準備しました。そしてGeoJSONをインポート用のJSONに事前修正しました。

img


今回のサンプルデータをGitHubに登録したのでぜひご利用ください。
sample data


これで事前のGISデータの準備は完了です!



ドメイン作成

Amazon OpenSearch Serviceでドメインを作成する方法です。


AWSマネジメントコンソール → Amazon OpenSearch Serviceをクリック。

img


「Create domain」をクリック。

img


ドメイン名・デプロイタイプ・自動調整を設定。

img


データノード・専用マスターノードを設定。

img


ネットワーク・きめ細かなアクセスコントロール・アクセスポリシーを設定
ユーザー名とパスワードを入力しユーザーを作成する。 ネットワークは今回デモのためパブリックアクセスで設定しました。

img


暗号化を設定 → 「作成」をクリック。

img


しばらく待つと環境構築が完了します。

img


これでドメインの作成は完了です!



OpenSearch Dashboardsに接続

Amazon OpenSearch ServiceでOpenSearch Dashboardsに接続する方法です。


OpenSearch DashboardsのURLをクリック。

img


ドメイン作成時に設定したユーザー名とパスワードを入力 → 「Log In」をクリック。

img


OpenSearch Dashboardsに接続されます。

img


これでOpenSearch Dashboardsの接続は完了です!



位置情報データ登録

Amazon OpenSearch Serviceで位置情報データを登録する方法です。


OpenSearch Dashboardsに接続 →「Dev Tools」をクリック。

img


位置情報データ用のインデックスを設定。今回は「geo_shape」を利用しました。

PUT point_geo_sample
{
  "mappings": {
        "properties": {
            "geometry": {
                "type": "geo_shape"
            }
        }
  }
}

img


位置情報データをインポート。元データのGeoJSONをインポート用のJSONに事前修正してあります。

POST point_geo_sample/_bulk
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n260423690", "name": "文教堂書店", "shop": "books" }, "geometry": { "type": "Point", "coordinates": [ 139.7577071, 35.6678306 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n260424181", "name": "LABI", "shop": "electric" }, "geometry": { "type": "Point", "coordinates": [ 139.757034800000014, 35.6671262 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n260424208", "name": "キムラヤ", "shop": "electric" }, "geometry": { "type": "Point", "coordinates": [ 139.7577643, 35.665613 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n261024380", "name": "ソフトバンクショップ", "shop": "mobile_phone" }, "geometry": { "type": "Point", "coordinates": [ 139.7773429, 35.6772184 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n410500414", "name": "ミニストップ", "shop": "convenience" }, "geometry": { "type": "Point", "coordinates": [ 139.745115, 35.7081941 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n417434047", "name": "Inplexe", "shop": "accessories" }, "geometry": { "type": "Point", "coordinates": [ 139.7414085, 35.7005685 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n439115834", "name": "フォルクスワーゲン六本木", "shop": "car" }, "geometry": { "type": "Point", "coordinates": [ 139.7359042, 35.665522 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n474605269", "name": "Family Mart", "shop": "convenience" }, "geometry": { "type": "Point", "coordinates": [ 139.7499649, 35.6692143 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n474605283", "name": "セブン-イレブン", "shop": "convenience" }, "geometry": { "type": "Point", "coordinates": [ 139.7540003, 35.668082 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n474605289", "name": "Lawson", "shop": "convenience" }, "geometry": { "type": "Point", "coordinates": [ 139.754741599999988, 35.6676069 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n559359769", "name": "LAWSON 銀座6丁目店", "shop": "convenience" }, "geometry": { "type": "Point", "coordinates": [ 139.7657173, 35.6687584 ] } }
{"index": {}}
....

img


これで位置情報データの登録は完了です!



空間検索

最後に、Amazon OpenSearch Serviceで空間検索をする方法を紹介します。


今回の空間検索は下記のようなbbox内にあるポイントデータを検索してみます。事前にQGISでデータを可視化し検索したい左上と右下の経緯度を準備します。

img


空間検索をする条件を指定し左上と右下の経緯度を入力します。

POST point_geo_sample/_search
{
  "query":{
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "geo_shape": {
          "geometry": {
            "shape": {
              "type": "envelope",
              "coordinates" : [[139.7802, 35.6781], [139.7878, 35.6724]]
            },
              "relation": "within"
          }
        }
      }
    }
  }
}

検索結果がQGISの可視化と一致しました!

{
  "took" : 9,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 3,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "point_geo_sample",
        "_type" : "_doc",
        "_id" : "mdQ_54EBMGUV534vZahT",
        "_score" : 1.0,
        "_source" : {
          "type" : "Feature",
          "properties" : {
            "full_id" : "n1892534950",
            "name" : "セブン-イレブン",
            "shop" : "convenience"
          },
          "geometry" : {
            "type" : "Point",
            "coordinates" : [
              139.7819038,
              35.675297
            ]
          }
        }
      },
      {
        "_index" : "point_geo_sample",
        "_type" : "_doc",
        "_id" : "yNQ_54EBMGUV534vZa1Z",
        "_score" : 1.0,
        "_source" : {
          "type" : "Feature",
          "properties" : {
            "full_id" : "n3758524951",
            "name" : "セブン-イレブン",
            "shop" : "convenience"
          },
          "geometry" : {
            "type" : "Point",
            "coordinates" : [
              139.7859394,
              35.6769875
            ]
          }
        }
      },
      {
        "_index" : "point_geo_sample",
        "_type" : "_doc",
        "_id" : "KtQ_54EBMGUV534vZadN",
        "_score" : 1.0,
        "_source" : {
          "type" : "Feature",
          "properties" : {
            "full_id" : "n1215847202",
            "name" : "NATURAL LAWSON",
            "shop" : "convenience"
          },
          "geometry" : {
            "type" : "Point",
            "coordinates" : [
              139.781879,
              35.6744447
            ]
          }
        }
      }
    ]
  }
}

img


Amazon OpenSearch Serviceを利用することでインポートしたデータを空間検索することが可能になります!



Amazon OpenSearch ServiceとQGISについて、他にも記事を書いています。よろしければぜひ。
tags - Amazon OpenSearch Service
tags - QGIS



book

Q&A