OpenStreetMap のタイルサーバを構築するで作成した環境に、日本域のデータをインポートします。
目次
日本域データをダウンロード
日本域のデータをダウンロードします。約1.4GBあります。
$ wget https://download.geofabrik.de/asia/japan-latest.osm.pbf
PostgreSQL にインポート
ダウンロードしたデータをPostgreSQLにインポートします。
- 前回の環境構築時にテスト用にインポートしたアゼルバイジャンのデータを一応残しておきたいので、
--create
ではなく--append
にします。--append
を指定しないとデフォルトで--create
になり、DBの内容がクリアされてしまうため要注意です。 - メモリ割り当てを念のため2500MBから4000MBに増やしておきます。
- CPUよりもファイルI/Oがネックになるかと思い
--number-processes
は1のままにしましたが、増やせばひょっとしたら速くなったかもしれません。
前回 | osm2pgsql -d gis --create --slim -G --hstore --tag-transform-script ~/src/openstreetmap-carto/openstreetmap-carto.lua -C 2500 --number-processes 1 -S ~/src/openstreetmap-carto/openstreetmap-carto.style ~/data/azerbaijan-latest.osm.pbf |
今回 | osm2pgsql -d gis --append --slim -G --hstore --tag-transform-script ~/src/openstreetmap-carto/openstreetmap-carto.lua -C 4000 --number-processes 1 -S ~/src/openstreetmap-carto/openstreetmap-carto.style ~/data/japan-latest.osm.pbf |
$ osm2pgsql -d gis --append --slim -G --hstore --tag-transform-script ~/src/openstreetmap-carto/openstreetmap-carto.lua -C 4000 --number-processes 1 -S ~/src/openstreetmap-carto/openstreetmap-carto.style ~/data/japan-latest.osm.pbf osm2pgsql version 1.2.0 (1.2.0-396-g5caa410) Allocating memory for dense node cache Allocating dense node cache in one big chunk Allocating memory for sparse node cache Sharing dense sparse Node-cache: cache=4000MB, maxblocks=64000*65536, allocation method=11 Mid: pgsql, cache=4000 Using lua based tag processing pipeline with script /home/renderaccount/src/openstreetmap-carto/openstreetmap-carto.lua Using projection SRS 3857 (Spherical Mercator) Setting up table: planet_osm_point Setting up table: planet_osm_line Setting up table: planet_osm_polygon Setting up table: planet_osm_roads Reading in file: /home/renderaccount/data/japan-latest.osm.pbf Using PBF parser. Processing: Node(184075k 5.9k/s) Way(23658k 0.76k/s) Relation(83290 40.7/s) parse time: 64349s Node stats: total(184075264), max(7472231102) in 31185s Way stats: total(23658371), max(798953401) in 31119s Relation stats: total(83290), max(11057963) in 2045s Going over pending ways... 112 ways are pending Using 1 helper-processes Finished processing 112 ways in 3 s 112 Pending ways took 3s at a rate of 37.33/s Going over pending relations... 87 relations are pending Using 1 helper-processes Finished processing 87 relations in 25 s 87 Pending relations took 25s at a rate of 3.48/s Completed planet_osm_point Completed planet_osm_line Completed planet_osm_polygon Completed planet_osm_roads Stopping table: planet_osm_nodes Stopped table: planet_osm_nodes in 0s Stopping table: planet_osm_ways Stopped table: planet_osm_ways in 0s Stopping table: planet_osm_rels Stopped table: planet_osm_rels in 0s Osm2pgsql took 64428s overall node cache: stored: 184075264(100.00%), storage efficiency: 52.70% (dense blocks: 6626, sparse nodes: 147501249), hit rate: 99.98%
トータル64428秒ということで、約18時間かかりました。
なお、今回使用した環境は以下の通りです。
- ホストマシン: Core i7-8700 @ 3.20GHz、DDR4 32GB、HDD 5400RPM SATA/600、Windows 10
- ゲストマシン: VirtualBox 6.1、CPU×2、メモリ 8GB、Ubuntu 20.04、PostgreSQL 12
- 地図データ: 日本(今回インポート)、アゼルバイジャン(タイルサーバ構築当初の動作確認用にインポートしていた)
インポート後のレコード件数は以下のとおりです。だいぶ増えました。
$ sudo su - postgres $ psql gis psql (12.2 (Ubuntu 12.2-4)) Type "help" for help. gis=# select relname, n_live_tup from pg_stat_user_tables where schemaname='public'; relname | n_live_tup --------------------+------------ planet_osm_roads | 610310 planet_osm_nodes | 186422289 planet_osm_ways | 23726279 spatial_ref_sys | 8500 planet_osm_polygon | 14438037 planet_osm_point | 1996382 planet_osm_line | 9038265 planet_osm_rels | 86139 (8 rows)
テーブル名 | 環境構築+アゼルバイジャンインポート後 | 今回さらに日本インポート後 | 増加 |
---|---|---|---|
planet_osm_roads | 9,904 | 610,310 | 600,406 |
planet_osm_nodes | 3,002,231 | 186,422,289 | 183,420,058 |
planet_osm_ways | 281,242 | 23,726,279 | 23,445,037 |
spatial_ref_sys | 8,500 | 8,500 | 0 |
planet_osm_polygon | 108,666 | 14,438,037 | 14,329,371 |
planet_osm_point | 52,271 | 1,996,382 | 1,944,111 |
planet_osm_line | 171,374 | 9,038,265 | 8,866,891 |
planet_osm_rels | 2,850 | 86,139 | 83,289 |
合計 | 3,637,038 | 236,326,201 | 232,689,163 |
地図を表示
OpenStreetMap のタイルサーバを構築するで動作確認に使用したsample_leaflet.htmlを日本用に書き換えてブラウザからアクセスしてみます。前回はアゼルバイジャンの経緯度が書いてありましたが、今回は日本の経緯度として北緯35度、東経135度を指定します。
/var/www/html/sample_leaflet.html
<!DOCTYPE html> <html style="height:100%;margin:0;padding:0;"> <title>Leaflet page with OSM render server selection</title> <meta charset="utf-8"> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3/dist/leaflet.css" /> <script src="https://unpkg.com/leaflet@1.3/dist/leaflet.js"></script> <script src="https://unpkg.com/leaflet-hash@0.2.1/leaflet-hash.js"></script> <style type="text/css"> .leaflet-tile-container { pointer-events: auto; } </style> </head> <body style="height:100%;margin:0;padding:0;"> <div id="map" style="height:100%"></div> <script> //<![CDATA[ var map = L.map('map').setView([35, 135], 18); L.tileLayer('http://192.168.56.101/hot/{z}/{x}/{y}.png', { attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' }).addTo(map); var hash = L.hash(map) //]]> </script> </body> </html>
http://サーバのドメインまたはIPアドレス/sample_leaflet.html
