コンテンツへスキップ

OpenStreetMap の日本域データをインポート

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_roads9,904610,310600,406
planet_osm_nodes3,002,231186,422,289183,420,058
planet_osm_ways281,24223,726,27923,445,037
spatial_ref_sys8,5008,5000
planet_osm_polygon108,66614,438,03714,329,371
planet_osm_point52,2711,996,3821,944,111
planet_osm_line171,3749,038,2658,866,891
planet_osm_rels2,85086,13983,289
合計3,637,038236,326,201232,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

コメントを残す

%d人のブロガーが「いいね」をつけました。