Tool for converting from PostGIS to 3D Tiles/b3dm tiles. This software is a partial port of py3dtiles (https://github.com/Oslandia/py3dtiles) for generating b3dm tiles.
Differences to py3dtiles:
-
2* performance improvement;
-
loading geometries in batches in memory instead of full datataset;
-
fixed glTF warnings;
-
added styling options like roof color column per geometry/triangle;
-
added output directory option;
-
Docker support.
To run this tool there must be a PostGIS table available containing triangulated polyhedralsurface geometries.
Tileset.json and b3dm tiles are by default created in the 'output/tiles' subdirectory (or specify directory with -o, --output).
- Texel - 3D Terrain, subsurface and buildings in MapBox GL JS: http://beta.geodan.nl/mapbox3d
-
GeoTop Subsurface in MapBox GL JS: https://geodan.github.io/pg2b3dm/sample_data/geotop/mapbox/
-
Amsterdam Buildings in MapBox GL JS: https://geodan.github.io/pg2b3dm/sample_data/amsterdam/mapbox/
-
Amsterdam Buildings in Cesium: https://geodan.github.io/pg2b3dm/sample_data/amsterdam/cesium/
-
Dover - Delaware buildings in MapBox GL JS: https://geodan.github.io/pg2b3dm/sample_data/delaware/mapbox/
-
Dover - Delaware buildings in Cesium: https://geodan.github.io/pg2b3dm/sample_data/delaware/cesium/
-
Duisburg buidings converted from CityGML in MapBox GL JS - https://geodan.github.io/pg2b3dm/sample_data/duisburg/mapbox/#15.62/51.430166/6.782675/0/45
All parameters are optional, except the -t --table option.
If --username and/or --dbname are not specified the current username is used as default.
-U, --username (Default: username) Database user
-h, --host (Default: localhost) Database host
-d, --dbname (Default: username) Database name
-c, --column (Default: geom) Geometry column name
-i, --idcolumn (Default: id): Identifier column
-t, --table (Required) Database table name, include database schema if needed
-o, --output (Default: ./output/tiles) Output directory, will be created if not exists
-p, --port (Default: 5432) Database port
-r, --roofcolorcolumn (Default: '') color column name
-a, --attributescolumn (Default: '') attributes column name
-f, --featurespertile (Default: 50) Maximum features per tile
-e, --extenttile (Default: 2000) Maximum extent per tile
--help Display this help screen.
--version Display version information.
Geometry rules:
- All geometries must be type polyhedralsurface consisting of triangles with 4 vertices each. If not 4 vertices exception is thrown.
Color column rules:
-
Colors must be specified as hex colors, like '#ff5555';
-
If no color column is specified, a default color (#bb3333) is used for all buildings;
-
If color column is specified and database type is 'text', 1 color per building is used;
-
If color column is specified and database type is 'text[]', 1 color per triangle is used. Exception is thrown when number
of colors doesn't equal the number of triangles in geometry. Order of colors must be equal to order of triangles.
- Transparency (alpha channel) can be used, possible values:
100% — FF 95% — F2 90% — E6 85% — D9 80% — CC 75% — BF 70% — B3 65% — A6 60% — 99 55% — 8C 50% — 80 45% — 73 40% — 66 35% — 59 30% — 4D 25% — 40 20% — 33 15% — 26 10% — 1A 5% — 0D 0% — 00
100% means opaque, 0% means transparent
Id column rules:
-
Id column must be type string;
-
Id column should be indexed for better performance.
See getting started for a tutorial how to run pg2b3dm and visualize buildings in MapBox GL JS or Cesium.
For a dataprocessing workflow from CityGML to 3D Tiles using GDAL, PostGIS and FME see dataprocessing/dataprocessing_citygml.
Docker image: https://hub.docker.com/repository/docker/geodan/pg2b3dm
Tags used (https://hub.docker.com/repository/docker/geodan/pg2b3dm/tags):
-
0.5, 0.6, 0.7, 0.8 release
-
latest: latest release
$ docker build -t geodan/pg2b3dm .
Sample on Windows:
$ docker run -v C:\output:/app/output -it geodan/pg2b3dm -h my_host -U my_user -d my_database -t my_table
Sample on Linux:
$ docker run -v $(pwd)/output:/app/output -it geodan/pg2b3dm -h my_host -U my_user -d my_database -t my_schema.my_table
Requirement: Install .NET Core 3.1 SDK
https://dotnet.microsoft.com/download/dotnet-core/3.1
TL;DR:
$ sudo apt-get update
$ sudo apt-get install apt-transport-https
$ sudo apt-get update
$ sudo apt-get install dotnet-sdk-3.1
Build app:
$ git clone https://github.com/Geodan/pg2b3dm.git
$ cd pg2b3dm/src
$ dotnet build
$ dotnet run
To create an self-contained executable '~/bin/pg2b3dm':
$ git clone https://github.com/Geodan/pg2b3dm.git
$ cd pg2b3dm/src/pg2b3dm
$ dotnet publish -c Release -r linux-x64 /p:PublishSingleFile=true
$ cp ./bin/Release/netcoreapp3.1/linux-x64/publish/pg2b3dm ~/bin
$ ~/bin/pg2b3dm
$ git clone https://github.com/Geodan/pg2b3dm.git
$ cd src
$ code .
In Visual Studio Code, open .vscode/launch.json and adjust the 'args' parameter to your environment
"args": ["-h" ,"my_host", "-U" ,"my_user", "-d", "my_database", "-t", "my_table"],
Press F5 to start debugging.
-
SharpGLTF (https://github.com/vpenades/SharpGLTF) for generating glTF;
-
CommandLineParser (https://github.com/commandlineparser/commandline) for parsing command line options;
-
Npgsql (https://www.npgsql.org/) - for access to PostgreSQL;
-
b3dm-tile (https://github.com/bertt/b3dm-tile-cs) - for generating b3dm files;
-
Wkx (https://github.com/cschwarz/wkx-sharp) - for geometry handling.
2019-11-18: release 0.8 adding -f, --featurespertile and -e, --extenttile options
2019-10-02: release 0.7 adding id column option (default 'id')
2019-09-02: release 0.6 adding batching option on single column (-a option)
2019-08-21: release 0.5.1 with fix for non trusted Postgres connection
2019-08-20: release 0.5 adds support for multiple colors
2019-08-15: release 0.4.4 improving roof colors
2019-08-15: release 0.4.3 change degenerated triangles detection + removal
2019-08-14: release 0.4.2 fixing roof colors + filter very small triangles (<0.01)
2019-08-13: release 0.4.1 with fix for roof colors (option -r)
2019-08-12: release 0.4 adding roof color column option (-r)
2019-08-01: release 0.3.3 with 2 colors
2019-07-09: release 0.3 using library SharpGLTF
2019-06-01: release 0.2.1 with some small fixes
2019-06-01: initial release 0.2
2019-05-01: initial release 0.1