0. 前提
- osrmのセットアップが終わっている事
- curlが使えること(ブラウザでもいいけど)
- wgetが使えること(ブラウザでもいいけど)
ディレクトリ構成
/home/tomonobu/work/
osrm-backend/ ... osrmをインストールしたディレクトリ
osm/ ... osmデータ用ディレクトリ
kanto/ ... 関東
berlin/ ... ベルリン
1. OSMデータのダウンロード
関東 http://download.geofabrik.de/asia/japan/kanto-latest.osm.pbf
$ pwd
/home/tomonobu/work/osm/kanto <== ここのディレクトリにダウンロードする
$ wget http://download.geofabrik.de/asia/japan/kanto-latest.osm.pbf
2. OSMデータの展開
実行は osrmをインストールしたディレイクトリで
$ pwd
/home/tomonobu/work/osrm-backend
$ osrm-extract ../osm/kanto/kanto-latest.osm.pbf
$ osrm-partition ../osm/kanto/kanto-latest.osrm
$ osrm-customize ../osm/kanto/kanto-latest.osrm
3. サーバ起動
$ osrm-routed --ip 127.0.0.1 --port 5000 --algorithm mld ../osm/kanto/kanto-latest.osrm
4. 始点と終点の緯度経度を決めよう
Googleマップ → 右クリックで「この場所について」
- 始点 35.1617517,139.728336
- 終点 35.656327,139.792895
5. ルート作成
$ curl --noproxy 127.0.0.1 'http://127.0.0.1:5000/route/v1/driving/139.728222,35.617534;139.792895,35.656327?alternatives=3&geometries=geojson' | jq 'def hexdec(i): "0123456789abcdef"[i:i+1]; {"type": "FeatureCollection", "features": [[.routes[].geometry] | [., keys] | transpose[] | {"geometry": .[0], "type": "Feature", "properties": {"stroke-width": 2, "stroke": ("#" + hexdec(15-.[1]*2) + hexdec(.[1]*2) + hexdec(.[1]*2))}}]}' > routes_kanto2.json
==> 成功
6. ルート表示
出来上がった routes_kanto2.json を
http://geojson.io
に食わせれば、ルートが表示される
EOF