LoginSignup
6
8

More than 5 years have passed since last update.

時系列データを地図に可視化する①

Posted at

調べてもあまり出てこないから,メモがてら.

前準備

地図を表示したりするまでの準備

ツールのインストール

  • gdal
  • ogr2ogr
  • topojson

この3つが必要.インストール方法はいくらでもあるので割愛.
自分はhomebrewとnpmで入れた.

データの入手,整形

ダウンロード

いろいろとあるけど,自分は国土交通省から.
東京都だけを抜き出してダウンロード.
アンケートとか必要だった.平成26年度のものを選んだ.

GeoJSONの作成

拡張子がshpのものが必要
バイナリだから,中身を見るには

$ ogrinfo -al N03-14_13_140401.shp | nkf -w | head -n 20 | less

INFO: Open of `N03-14_13_140401.shp'
      using driver `ESRI Shapefile' successful.

Layer name: N03-14_13_140401
Geometry: Polygon
Feature Count: 3297
Extent: (136.069482, 20.425119) - (153.986898, 35.898424)
Layer SRS WKT:
GEOGCS["GCS_JGD_2000",
    DATUM["Japanese_Geodetic_Datum_2000",
        SPHEROID["GRS_1980",6378137.0,298.257222101]],
    PRIMEM["Greenwich",0.0],
    UNIT["Degree",0.0174532925199433]]
N03_001: String (10.0)
N03_002: String (20.0)
N03_003: String (20.0)
N03_004: String (20.0)
N03_007: String (5.0)
OGRFeature(N03-14_13_140401):0
  N03_001 (String) = 東京都
  N03_002 (String) = (null)
  N03_003 (String) = 西多摩郡
  N03_004 (String) = 奥多摩町
  N03_007 (String) = 13308
  POLYGON ((139.100223 35.867104...

今回は東京都の島しょ部を除いた部分が欲しかったから,
N003_007(行政区域コード)で13360未満のものだけ抽出.(島しょ部は13600以降)

$ ogr2ogr -f GeoJSON -where "N03_007 < '13360'" tokyo_honshu.geojson N03-14_13_140401.shp

TopoJSONの作成

GeoJSONをTopoJSONっていう圧縮したもの?に変換する.
とりあえず中身を見ると

$ less tokyo_honshu.geojson

{
"type": "FeatureCollection",

"features": [
{ "type": "Feature", "properties": { "N03_001": "東京都", "N03_002": null, "N03_003": "西多摩郡", "N03_004": "奥多摩町", "N03_007": "13308" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 139.100223, 35.867104 ], [ 139.100419000000102, 35.866862 ], [ 139.100845, 35.866292 ], [ 139.101117, 35.86603 ], [ 139.101137, 35.865995 ], [...

後々で使うかもしれなかったからTopoJSONに変換する際に,
区市?(N03_003)と町村?(N03_004)をプロパティとして追加して,行政区域コード(N03_007)をIDとして追加することに.
さらに区とかに名前を書き換えるため"変換後"="変換前"っていうのも加える.

$ topojson --id-property N03_007 -p shi=N03_004 -p ku=N03_003 -o tokyo_honshu.topojson tokyo_honshu.geojson

これでtokyo_honshu.topojsonっていうファイルができる.

参考

http://tactosh.com/2014/04/d3-js-japan-geo-map/
http://kshigeru.blogspot.jp/2013/03/d3-geojson-polygon.html

6
8
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
6
8