LoginSignup
18
14

More than 1 year has passed since last update.

GeoJSONデータの作成

Last updated at Posted at 2021-08-16

はじめに

WEBマップで利用する代表的なデータであるGeoJSONについて,入門者向けに解説したものです。以下では,テキストエディタを用いて,点,線,面のようなジオメトリやデータの属性情報の記述手法について記します。

GeoJSONとは

GeoJSONは、JavaScript Object Notation (JSON) を基礎とした,GISデータを記述するためのフォーマットです(地理空間データ交換フォーマット)。この形式では,Point, LineString, Polygon, MultiPoint,
MultiLineString, MultiPolygon, Geometry Collectionをサポートしています。軽量言語であり,Web GISでの利用例が多く見られます。GitHubには,GeoJSONの地図表示機能があり,リポジトリにデータを配置するだけで可視化が可能です。以下では,GeoJSONで点,線,面を記述する手法について解説します。

GeoJSONオブジェクト

GeoJSONのデータは,メンバー(名前と値)の集合体であるオブジェクトとして構成される。オブジェクトには,ジオメトリオブジェクト(coordinatesが必要),フィーチャーオブジェクト(geometry, propertiesが必要),フィーチャーコレクションオブジェクト(featuresが必要)などがある。以下では,ジオメトリオブジェクトを中心に解説する。ジオメトリオブジェクトには,typeがPoint, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, Geometry Collectionが選択でき,GeometryCollection以外は、測地座標系を示すcoordinatesをもつ。

データの作成

点データの作成

以下では,点の記述手法について解説します。任意のテキストエディタを開き,新規ファイルを作成後,.geojsonの拡張子で保存してください。

1地点の場合(富士山の山頂を表示)

GeoJSONで1地点のポイントレイヤを作成する際は,以下のように記述する。

{ "type": "Point",
  "crs": { "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
       }
      },
  "coordinates": [138.7309, 35.3628]
 }
  • 最初のtypeは,"Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "Geometry Collection", "Feature", および"FeatureCollection"のいずれかになる。
  • 上記の"crs"は,Named CRSとし,"properties"からWGS84を指定した。
  • "coordinates"は,経度,緯度,(高度)の順で並べる。

2地点の場合(富士山と愛鷹山の山頂を表示)

{ "type": "MultiPoint",
  "crs": { "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
       }
      },
  "coordinates": [[138.7309, 35.3628],[138.8079, 35.1983]]
 }
  • 最初の"type""MultiPoint"にする
  • "coordinates"に,愛鷹山の位置情報を追加

2地点の場合(FeatureCollectionで表示)

複数のフィーチャーを同ファイル内に記述する場合,以下のように"FeatureCollection"を使用する。

{ "type": "FeatureCollection",
  "crs": { "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
       }
      },
  "features": [
    { "type": "Feature",
      "properties": { },
      "geometry": {
         "type": "Point",
         "coordinates": [138.7309, 35.3628]
 }},
    { "type": "Feature",
       "properties": { },
       "geometry": {
          "type": "Point",
          "coordinates": [138.8079, 35.1983]
  }}
  ]
}

属性情報の記述

属性情報は,以下のように"features"の下層の"properties"に記述する。

{ "type": "FeatureCollection",
  "crs": { "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
       }
      },
  "features": [
    { "type": "Feature",
      "properties": { "id": 1, "name": "fujisan" },
      "geometry": {
         "type": "Point",
         "coordinates": [138.7309, 35.3628]
 }},
    { "type": "Feature",
       "properties": { "id": 2, "name": "ashitakayama" },
       "geometry": {
          "type": "Point",
          "coordinates": [138.8079, 35.1983]
  }}
  ]
}

線データの作成

線は,"type""LineString"を選択し,以下のように記述する。

{ "type": "LineString",
  "crs": { "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
       }
      },
  "coordinates": [[138.7309, 35.3628],[138.8079, 35.1983]]
 }

面データの作成

面は,"type""Polygon"を選択し,以下のように記述する。このとき,"coordinates"の始点と終点の座標を同じにすることと,[]の数に注意する。

{ "type": "Polygon",
  "crs": { "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
       }
      },
  "coordinates": [[[138.7309, 35.3628],[138.8079, 35.1983],[139.0248, 35.2248],[138.7309, 35.3628]]]
 }

点・線・面を一つのGeoJSONで表示(FeatureCollectionで表示)

以下のようにすると,一つのGeoJSONファイル内に,異なる形状のフィーチャーをまとめて記述することができる。

{ "type": "FeatureCollection",
  "crs": { "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
       }
      },
  "features": [
    { "type": "Feature",
      "properties": { },
      "geometry": {
         "type": "MultiPoint",
         "coordinates": [[138.7309, 35.3628], [138.8079, 35.1983],[139.0248, 35.2248]]
 }
},
    { "type": "Feature",
       "properties": { },
       "geometry": {
          "type": "LineString",
          "coordinates": [[138.7309, 35.3628], [138.8079, 35.1983],[139.0248, 35.2248]]
  }},
     { "type": "Feature",
        "properties": { },
        "geometry": {
           "type": "Polygon",
           "coordinates": [[[138.7309, 35.3628],[138.8079, 35.1983],[139.0248, 35.2248],[138.7309, 35.3628]]]
   }}
  ]
}
18
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
14