はじめに
Amazon Location Service が6月に一般公開されました。
主な機能として以下の5つがあります。
- 地図
- ジオコーディング(住所や場所の名前を緯度経度に変換する)やリバースジオコーディング(緯度経度を住所に変換する)
- 出発地から目的地までのルート計算
- 位置情報デバイスのトラッキング
- ジオフェンシング(設定した領域への出入りを検出する)
このうちのジオコーディングを試してみました。
ジオコーディングを AWS CLI から利用する
今回は AWS CLI からジオコーダを呼び出します。Location Service は新しいサービスなので、aws コマンドがインストール済みの場合は aws help で Location がサポートされているバージョンかどうかを確認し、サポートされていない場合は最新版にアップデートしておきます。
Place Index 作成
Place Index はジオコーダやリバースジオコーダを利用する際に必要となるリソースです。いくつかの設定項目を指定して Place Index を作成しておき、その Place Index を起点にジオコーダを呼び出す仕組みになっています。
以下のコマンドで、データソースとして Esri、料金プランとしてリクエスト数ベースを利用する Place Index を ExamplePlaceIndex という名前で呼び出せるようになります。
$ aws location \
> create-place-index \
> --data-source "Esri" \
> --description "for investigation Esri" \
> --index-name "ExamplePlaceIndex" \
> --pricing-plan "RequestBasedUsage"
{
"CreateTime": "2021-06-12T13:46:09.170000+00:00",
"IndexArn": "arn:aws:geo:us-west-2:495463288701:place-index/ExamplePlaceIndex",
"IndexName": "ExamplePlaceIndex"
}
Place Index 確認
以下のコマンドで、作成した Place Index の内容を確認できます。
$ aws location list-place-indexes
{
"Entries": [
{
"CreateTime": "2021-06-12T13:46:09.170000+00:00",
"DataSource": "Esri",
"Description": "for investigation Esri",
"IndexName": "ExamplePlaceIndex",
"PricingPlan": "RequestBasedUsage",
"UpdateTime": "2021-06-12T13:46:09.170000+00:00"
}
]
}
ジオコーディング
ジオコーダを利用するときは search-place-index-for-text というサブコマンドを使います。
$ aws location search-place-index-for-text \
--index-name ExamplePlaceIndex \
--text "大阪市中央区" \
--max-results 5
{
"Results": [
{
"Place": {
"Country": "JPN",
"Geometry": {
"Point": [
135.50988413000005,
34.681143990000066
]
},
"Label": "大阪府大阪市中央区",
"Municipality": "中央区",
"Region": "大阪府"
}
}
],
"Summary": {
"DataSource": "Esri",
"MaxResults": 10,
"ResultBBox": [
135.50988413000005,
34.681143990000066,
135.50988413000005,
34.681143990000066
],
"Text": "大阪市中央区"
}
}
「大阪市中央区」の緯度経度が(34.681143990000066,135.50988413000005)であるという応答です。この座標を OpenStreetMap で表示すると、確かに大阪市中央区役所であることが確認できます。
https://www.openstreetmap.org/#map=19/34.681143990000066/135.50988413000005/
データソースとして HERE を使う Place Index 作成
Amazon Location Service ではデータソースとして Esri と HERE が利用できます。ここではデータソースとして HERE を指定して、Esri のときとどのような違いがあるかを調べてみます。
$ aws location \
create-place-index \
--data-source "Here" \
--description "for investigation HERE" \
--index-name "ExamplePlaceIndexHERE" \
--pricing-plan "RequestBasedUsage"
$ aws location list-place-indexes
{
"Entries": [
{
"CreateTime": "2021-06-12T13:46:09.170000+00:00",
"DataSource": "Esri",
"Description": "for investigation Esri",
"IndexName": "ExamplePlaceIndex",
"PricingPlan": "RequestBasedUsage",
"UpdateTime": "2021-06-12T13:46:09.170000+00:00"
},
{
"CreateTime": "2021-06-12T14:12:51.610000+00:00",
"DataSource": "Here",
"Description": "for investigation HERE",
"IndexName": "ExamplePlaceIndexHERE",
"PricingPlan": "RequestBasedUsage",
"UpdateTime": "2021-06-12T14:12:51.610000+00:00"
}
]
}
HERE でジオコーディング
Esri のときと同じく「大阪市中央区」でジオコーディングします。
$ aws location search-place-index-for-text \
--index-name ExamplePlaceIndexHERE \
--text "大阪市中央区" \
--max-results 5
{
"Results": [
{
"Place": {
"Country": "JPN",
"Geometry": {
"Point": [
135.50988,
34.68114
]
},
"Label": "大阪府大阪市中央区",
"Municipality": "大阪市",
"Neighborhood": "中央区",
"Region": "大阪府"
}
},
{
"Place": {
"Country": "JPN",
"Geometry": {
"Point": [
135.5014,
34.66891
]
},
"Label": "大阪府大阪市中央区道頓堀1丁目6ミナミ (難波)",
"Municipality": "大阪市",
"Neighborhood": "中央区",
"Region": "大阪府"
}
},
{
"Place": {
"AddressNumber": "27",
"Country": "JPN",
"Geometry": {
"Point": [
135.50398,
34.69353
]
},
"Label": "大阪府大阪市北区中之島1丁目1-27大阪市中央公会堂",
"Municipality": "大阪市",
"Neighborhood": "北区",
"Region": "大阪府"
}
},
{
"Place": {
"Country": "JPN",
"Geometry": {
"Point": [
135.48485,
34.69745
]
},
"Label": "大阪府大阪市福島区福島7丁目4ジェイホッパーズ大阪ゲストハウス",
"Municipality": "大阪市",
"Neighborhood": "福島区",
"Region": "大阪府"
}
},
{
"Place": {
"Country": "JPN",
"Geometry": {
"Point": [
135.50791,
34.68903
]
},
"Label": "大阪府大阪市中央区伏見町1丁目1ホテルブライトンシティ大阪北浜",
"Municipality": "大阪市",
"Neighborhood": "中央区",
"Region": "大阪府"
}
}
],
"Summary": {
"DataSource": "Here",
"MaxResults": 5,
"ResultBBox": [
135.48485,
34.66891,
135.50988,
34.69745
],
"Text": "大阪市中央区"
}
}
sri の場合は max-results を 5 で指定していても応答は1件だけでしたが、HERE の場合は 住所が大阪市中央区でないPOIでもアグレッシブに応答しており、ジオコーダとしての性格がかなり異なることが分かります。