Tutorials3D City Database

3D City Database

The 3D City Database is a free 3D geo database for storing, representing, and managing semantic 3D city models. The database enables the execution of spatio-semantic queries on the semantic models and its upcoming version 5 also supports CityGML 3.0.

Starting the database as Docker container

To build a Docker image of the 3D City Database, run the following commands:

git clone --depth 1 -b v5-devel https://github.com/3dcitydb/3dcitydb.git
cd 3dcitydb
docker build -t 3dcitydb .

This 3D City Database image is built on top of the relational database PostgreSQL and the extension PostGIS, which provides a rich set of geospatial functions. To start the container, execute the command:

docker run --name 3dcitydb -p 5432:5432 -d \
    -e SRID=25832 \
    -e HEIGHT_EPSG=7837 \
    -e SRS_NAME=urn:ogc:def:crs:EPSG::25832 \
    -e POSTGRES_DB=citydb \
    -e POSTGRES_USER=postgres \
    -e POSTGRES_PASSWORD=changeMe \
    -e POSTGIS_SFCGAL=true \
  3dcitydb

Importing datasets

The citydb-tool is an accompanying CLI tool with which datasets can be imported and exported.

git clone https://github.com/3dcitydb/citydb-tool
cd citydb-tool && chmod +x ./gradlew

It supports the import of CityGML 2.0 and 3.0 datasets into the database with the following command:

./gradlew run --args='import citygml --db-host localhost --db-port 5432 --db-name citydb --db-username postgres --db-password changeMe ~/path/to/citygml/datasets'
ℹ️

The import of a few LOD3 building models, such as the building with ID DEBY_LOD3_4959460, can take up to 25 minutes, as it is very detailed and contains a lot of geometries.

Executing spatio-semantic queries

Run a simple query, such as:

SELECT *
FROM geometry_data
JOIN feature ON feature.id = geometry_data.feature_id
WHERE ST_3DDFullyWithin(geometry_data.geometry,
                      'SRID=25832;POINT(691045.978 5336015.44 519.269)'::geometry, 25);