3D City DB とは
3D City DB は、3D 都市モデルをデータベース上で管理・分析するためのデータベーススキーマと、インポーター / エクスポーター、ビューアーなど一連のツールを含む、オープンソースのパッケージです。
データベースは Oracle Spatial and Graph
と PostGIS
に対応しており、CityGML のフォマットに対応したスキーマを持ちます。
3D City DB には Docker イメージも用意されており、簡単に環境を構築することができます。
今回は PostgreSQL + PostGIS のイメージを使って構築したデータベースに、CityGML ファイルをインポートしてみます。
使用環境
Mac OS Big Sur 11.2.3
Docker Desktop 3.2.2
TablePlus
使用する Docker Image のリポジトリ
3D City Database PostGIS Docker image
https://github.com/tum-gis/3dcitydb-docker-postgis/
3DCityDB Importer/Exporter Docker
https://github.com/tum-gis/3dcitydb-importer-exporter-docker
手順
Docker の準備
Docker がインストールされていない場合は、以下からダウンロードしてセットアップして下さい。
3D City Database PostGIS Docker image のセットアップ
PostGIS (PostgreSQL) のイメージを使用します。
こちら のシェルスクリプトをダウンロードして実行します。
wget でダウンロードする場合
wget https://raw.githubusercontent.com/tum-gis/3dcitydb-docker-postgis/master/quickstart.sh
スクリプトを実行する
sh quickstart.sh
対話形式でパラメーターを設定します。今回はデフォルトパラメーターで進めます。
Please enter a NAME for the 3DCityDB PostGIS Docker container. Press ENTER to use default.
(default=citydb-container):
Please enter a PORT for the 3DCityDB PostGIS Docker container to listen on. Press ENTER to use default.
(default=5432):
Please enter a USERNAME for the 3DCityDB. Press ENTER to use default.
(default=postgres):
Please enter a PASSWORD for the 3DCityDB. Press ENTER to use default.
(default=postgres):
Please enter a DATABASE NAME for the 3DCityDB. Press ENTER to use default.
(default=citydb):
Please enter the SRID fof the spatial reference system of the 3DCityDB. Press ENTER to use default.
(default SRS=WGS84, SRID=4326):
Please enter the name of the spatial reference system to use for the 3DCityDB. Press ENTER to use default.
(default SRS=WGS84, SRSNAME=urn:ogc:def:crs:EPSG::4326):
citydb-container
コンテナが作成され、コンテナが起動します。
次回以降は docker start citydb-container
でコンテナを起動可能です。
docker ps
コマンドでコンテナの稼働状況を確認しましょう。
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
753ba67b90ba tumgis/3dcitydb-postgis "docker-entrypoint.s…" 6 weeks ago Up 14 seconds 0.0.0.0:5432->5432/tcp citydb-container
データベースの確認
TablePlus で DB へアクセスしてみます。
今回は Mac で無料で利用できる PostgreSQL クライアントとして、無料トライアル版の TablePlus を選択しました。
TablePlus が手元に無い方は、以下からダウンロードしてください。
デフォルトパラメーターでセットアップした場合は、下記の情報で接続可能かと思います。
Host/Socket: localhost
Port: 5432
User: postgres
Password: postgres
Database: citydb
テーブルが確認できれば OK です。
3DCityDB Importer/Exporter Docker で CityGML をインポート
まず、Importer/Exporter コンテナが参照可能なフォルダを作成します。
ここでは /my/local/share/folder
フォルダとします。
mkdir /my/local/share/folder -p
次にインポートする CityGML ファイルを配置します。
/my/local/share/folder/example.gml
データベース接続のため、citydb-container
の IP アドレスを確認します。
コンテナに入り hostname -i
で IP アドレスを確認しています。
docker exec -it citydb-container /bin/bash
hostname -i
172.17.0.2
docker run
でインポーターを実行します。
ここでは IP アドレス 172.17.0.2
を指定します。パラメーターは書き換えてください。
docker run --name impexp -i -t --rm \
-v /my/local/share/folder:/share \
tumgis/3dcitydb-importer-exporter import \
/my/local/share/folder/example.gml -H 172.17.0.2 -P 5432 -d citydb -u postgres -p postgres
以下のようなログが出力されてインポートが始まります。ファイルサイズによっては時間がかかります。
# 3DCityDB ImporterExporter Docker #############################################
################################################################################
# Official repo github.com/3dcitydb/importer-exporter
# Docker repo github.com/tum-gis/3dcitydb-importer-exporter-docker
# Version info -----------------------------------------------------------------
sha1 short 3ae3a2f
sha1 3ae3a2f7d69897a268711cebdaaa65c0be2c54fd
commit time Wed Jan 13 22:14:45 2021 +0100
branch master
# Maintainer -------------------------------------------------------------------
Bruno Willenborg
Chair of Geoinformatics
Department of Aerospace and Geodesy
Technical University of Munich (TUM)
b.willenborg(at)tum.de
www.gis.lrg.tum.de
################################################################################
Command line passed to 3DCityDB ImporterExporter:
import /my/local/share/folder/example.gml -H 172.17.0.2 -P 5432 -d citydb -u postgres -p postgres
[14:09:55 INFO] Starting 3D City Database Importer/Exporter, version 4.3.0
[14:09:55 INFO] Loading plugins
[14:09:55 INFO] Initializing plugin org.citydb.plugins.spreadsheet_gen.SPSHGPlugin
[14:09:55 INFO] Loading database schema mapping
[14:09:55 INFO] Loading ADE extensions
[14:09:55 INFO] Loading CityGML and ADE contexts
[14:09:57 INFO] Initializing application environment
[14:09:57 INFO] Executing 'import' command
[14:09:57 INFO] Connecting to database 'postgres@172.17.0.2:5432/citydb'.
[14:09:57 INFO] Database connection established.
[14:09:57 INFO] 3D City Database: 4.0.3
[14:09:57 INFO] DBMS: PostgreSQL 12.5 (Debian 12.5-1.pgdg100+1)
[14:09:57 INFO] Connection: postgres@172.17.0.2:5432/citydb
[14:09:57 INFO] Schema: citydb
[14:09:57 INFO] SRID: 4326 (Geographic2D)
[14:09:57 INFO] SRS: WGS 84
[14:09:57 INFO] gml:srsName: urn:ogc:def:crs:EPSG::4326
[14:09:57 INFO] Spatial indexes are enabled.
[14:09:57 INFO] Normal indexes are enabled.
[14:09:57 INFO] Creating list of files to be imported...
[14:09:57 INFO] List of import files successfully created.
[14:09:57 INFO] 1 file(s) will be imported.
[14:09:58 INFO] Importing file: /share/folder/example.gml
[14:10:02 INFO] Resolving XLink references.
[14:10:02 INFO] Cleaning temporary cache.
[14:10:02 INFO] Imported city objects:
[14:10:02 INFO] bldg:Building: 999
[14:10:02 INFO] Processed geometry objects: 9999
[14:10:02 INFO] Total import time: 04 s.
[14:10:02 INFO] Database import successfully finished.
Database import successfully finished.
と出れば完了です。
データベースへアクセスし、インポートされていることを確認しましょう。
まとめ
簡単にデータベース上に CityGML をインポートすることができました。
データベース上にデータがあると、分析や加工、アプリ開発が捗るのかなと思います。
同じような手順でデータベース上で管理しているデータをエクスポートすることも可能です。
詳しくは公式ドキュメントをご覧ください。