Skip to content

dev'geo_object'geo_json

Usagi Ito edited this page Dec 22, 2017 · 1 revision

GeoJSON を扱う

G4-4.0.0.11 ( preview-4 ) 以降に追加された GeoJSON を扱う機能について紹介します。この機能を用いると GeoJSON 形式のデータを G4 の地物システムへ読み込めます。

Note: 4.0.0.11 時点では GeoJSON の対応は試験的・部分的で、 Point 形式の Feature または FeatureCollection にのみ対応しています。

例1: 単一の Feature からなる最も単純な GeoJSON を読み込んでみる

北海道の著名な火山の1つ、羊蹄山を示す GeoJSON は次のように定義できます。

youteisan.geojson:

{ "type": "Feature"
, "geometry":
  { "type": "Point"
  , "coordinates": [ 140.811389, 42.826667 ]
  }
, "properties":
  { "name": "羊蹄山"
  }
}

この GeoJSON を G4 で読み込ませたい場合、 GeoObject.NewFromGeoJSON API を使用します。 API の params を含むリスエスト JSON は次のように定義できます。

request.youteisan.json:

{ "jsonrpc": "2.0"
, "id": null
, "method": "GeoObject.NewFromGeoJSON"
, "params":
  { "GeoJSON":
    { "type": "Feature"
    , "geometry":
      { "type": "Point"
      , "coordinates": [ 140.811389, 42.826667 ]
      }
    , "properties":
      { "name": "羊蹄山"
      }
    }
  }
}

このリクエストを curlPOST すると次のように羊蹄山をG4の地物システムへ読み込めます。

curl -Ss -i http://127.0.0.1:50080/api/json-rpc-2.0/ -X POST -d @request.youteisan.json

image

例2: 地理院地図の「指定緊急避難場所(地震)」ベクタータイルのデータを表示してみる

例として https://cyberjapandata.gsi.go.jp/xyz/skhb04/10/912/376.geojson のデータを読み込むリクエストは次のようになります。

request.gsi_skh04_10_912_376.json:

{ "jsonrpc": "2.0"
, "id": null
, "method": "GeoObject.NewFromGeoJSON"
, "params":
  { "GeoJSON":
    {"type":"FeatureCollection","features":[
    {"type":"Feature","geometry":{"type":"Point","coordinates":[140.73248811749,43.039277047092]},"properties":{"name":"銀山小学校グランド","address":"北海道仁木町銀山2丁目446番地","disaster1":1,"disaster4":1,"disaster6":1}},
    {"type":"Feature","geometry":{"type":"Point","coordinates":[140.72563244118,43.042264096845]},"properties":{"name":"銀山中学校グランド","address":"北海道仁木町銀山2丁目113番地","disaster1":1,"disaster2":1,"disaster4":1,"disaster6":1}},
    {"type":"Feature","geometry":{"type":"Point","coordinates":[140.76213107485,43.03786777423]},"properties":{"name":"長沢会館前","address":"北海道仁木町長沢南464番地2","disaster1":1,"disaster2":1,"disaster4":1,"disaster6":1}},
    {"type":"Feature","geometry":{"type":"Point","coordinates":[140.78652844805,43.037552143532]},"properties":{"name":"尾根内会館前","address":"北海道仁木町尾根内221番地4","disaster1":1,"disaster2":1,"disaster4":1,"disaster6":1}},
    {"type":"Feature","geometry":{"type":"Point","coordinates":[140.83610217177,43.049954911592]},"properties":{"name":"赤井川村立都小学校校舎","address":"北海道余市郡赤井川村字都113","disaster2":1,"disaster4":1,"disaster6":1,"disaster7":1}},
    {"type":"Feature","geometry":{"type":"Point","coordinates":[140.83558718765,43.049954911592]},"properties":{"name":"赤井川村立都小学校体育館","address":"北海道余市郡赤井川村字都113","disaster2":1,"disaster4":1,"disaster6":1,"disaster7":1}},
    {"type":"Feature","geometry":{"type":"Point","coordinates":[140.83681027496,43.050299879043]},"properties":{"name":"赤井川村立都小学校グラウンド","address":"北海道余市郡赤井川村字都113","disaster2":1,"disaster4":1,"disaster6":1,"disaster7":1}},
    {"type":"Feature","geometry":{"type":"Point","coordinates":[140.83290467531,43.051110200296]},"properties":{"name":"赤井川村都住民センター","address":"北海道余市郡赤井川村字都127-15","disaster2":1,"disaster4":1,"disaster6":1,"disaster7":1}},
    {"type":"Feature","geometry":{"type":"Point","coordinates":[140.84440948051,43.051395167595]},"properties":{"name":"村の駅あかいがわ","address":"北海道余市郡赤井川村字都190-16","disaster1":1,"disaster2":1,"disaster4":1,"disaster6":1,"disaster7":1}}
    ]}
  }
}

これを curl でリクエストすると次のような結果が得られます:

curl -Ss -i http://127.0.0.1:50080/api/json-rpc-2.0/ -X POST -d @request.gsi_skh04_10_912_376.json

image

Clone this wiki locally
You can’t perform that action at this time.