### Install pg2b3dm Pre-built Binary Source: https://context7.com/geodan/pg2b3dm/llms.txt Downloads and extracts a pre-built binary for Linux x64. Verify the installation by running the executable with the --version flag. ```bash wget https://github.com/Geodan/pg2b3dm/releases/download/2.27.0/pg2b3dm-linux-x64.zip unzip pg2b3dm-linux-x64.zip ./pg2b3dm --version ``` -------------------------------- ### Install pg2b3dm as .NET Global Tool Source: https://context7.com/geodan/pg2b3dm/llms.txt Installs or updates the pg2b3dm .NET global tool. Verify the installation using the --version flag. ```bash dotnet tool install -g pg2b3dm ``` ```bash dotnet tool update -g pg2b3dm ``` ```bash pg2b3dm --version ``` -------------------------------- ### Install pg2b3dm as .NET Tool Source: https://github.com/geodan/pg2b3dm/blob/master/README.md Instructions for installing or updating pg2b3dm globally using the .NET CLI. Requires .NET 8.0 SDK. ```bash $ dotnet tool install -g pg2b3dm ``` ```bash $ dotnet tool update -g pg2b3dm ``` ```bash $ pg2b3dm ``` -------------------------------- ### Install pg2b3dm via Windows Binary Source: https://github.com/geodan/pg2b3dm/blob/master/README.md Steps to download and extract pre-built binaries for Windows. Ensure you use the correct version number when downloading. ```bash $ wget https://github.com/Geodan/pg2b3dm/releases/download/{version}/pg2b3dm-win-x64.zip $ unzip pg2b3dm-win-x64.zip $ pg2b3dm ``` -------------------------------- ### VS Code launch.json Debug Arguments Source: https://github.com/geodan/pg2b3dm/blob/master/README.md Example configuration for the 'args' parameter in .vscode/launch.json to specify connection details for debugging the pg2b3dm application. ```json "args": ["-h" ,"my_host", "-U" ,"my_user", "-d", "my_database", "-t", "my_table"] ``` -------------------------------- ### Install 3DCityDB v5 Docker Image Source: https://github.com/geodan/pg2b3dm/blob/master/dataprocessing/dataprocessing_citygml.md Launches a Docker container for 3DCityDB v5, mapping ports and setting environment variables for the PostgreSQL database. ```bash docker run -d -p 5440:5432 -it -e POSTGRES_PASSWORD=postgres -e PROJ_NETWORK=ON -e SRID=7415 3dcitydb/3dcitydb-pg ``` -------------------------------- ### Sample Shader: PbrSpecularGlossiness with Diffuse and SpecularGlossiness Source: https://github.com/geodan/pg2b3dm/blob/master/src/release_notes_0.10.md Example JSON for applying PbrSpecularGlossiness shader, including DiffuseColors and SpecularGlossiness properties for two triangles. ```json { "PbrSpecularGlossiness": { "DiffuseColors": ["#E6008000","#E6008000"], "SpecularGlossiness": ["#4D0000ff", "#4D0000ff"] } } ``` -------------------------------- ### Sample pg2b3dm Command Execution Source: https://github.com/geodan/pg2b3dm/blob/master/README.md Example of how to run pg2b3dm with specific connection and output parameters. Database password may be prompted unless trusted authentication is enabled or PGPASSWORD is set. ```bash $ pg2b3dm --connection "Host=localhost;Username=postgres;Database=postgres;Ssl Mode=Require;CommandTimeOut=0" -c geom_triangle --shaderscolumn shaders -t delaware_buildings -g 100,0 ``` -------------------------------- ### Run pg2b3dm Docker Container Source: https://github.com/geodan/pg2b3dm/blob/master/getting_started.md This command starts a PostgreSQL container with PostGIS enabled, suitable for development and testing. ```bash docker run -it -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e PROJ_NETWORK=ON postgis/postgis:18-3.6 ``` -------------------------------- ### Apply Single Shader to All Triangles (Server-Side, Alternative) Source: https://github.com/geodan/pg2b3dm/blob/master/styling.md An alternative example for server-side styling where a single shader is applied to all triangles, demonstrating the JSON structure for PbrMetallicRoughness. ```json { "PbrMetallicRoughness": { "BaseColors": [ "#008000" ] } } ``` -------------------------------- ### Sample Shader: PbrMetallicRoughness with BaseColor Source: https://github.com/geodan/pg2b3dm/blob/master/src/release_notes_0.10.md Example JSON for applying PbrMetallicRoughness shader with BaseColor. This configuration is compatible with previous releases and specifies colors for two triangles. ```json { "PbrMetallicRoughness": { "BaseColors": ["#008000","#008000"] } } ``` -------------------------------- ### Example of LOD Functionality Source: https://github.com/geodan/pg2b3dm/blob/master/src/release_notes_0.9.md Illustrates how to enable and configure Level of Detail (LOD) functionality using the -l or --lodcolumn option, specifying the column name for LOD values. ```bash -l --lodcolumn ``` -------------------------------- ### Example of Geometric Errors Option Source: https://github.com/geodan/pg2b3dm/blob/master/src/release_notes_0.9.md Demonstrates the usage of the --geometricerrors option with multiple values, specifying geometric error thresholds for different levels. ```bash -g 1000,750,0 ``` -------------------------------- ### Create Self-Contained pg2b3dm Executable Source: https://github.com/geodan/pg2b3dm/blob/master/README.md Publish the pg2b3dm application as a self-contained executable for Linux. This command creates an executable file that can be run without requiring the .NET SDK to be installed on the target machine. ```bash $ 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/net8.0/linux-x64/publish/pg2b3dm ~/bin $ ~/bin/pg2b3dm ``` -------------------------------- ### Filter Data by Spatial Intersection Source: https://github.com/geodan/pg2b3dm/blob/master/README.md This example shows how to use the -q or --query parameter for spatial filtering. It selects features that intersect with a specified polygon defined by its SRID and coordinates. ```bash -q "ST_Intersects(wkb_geometry, 'SRID=4326;POLYGON((-75.56996406 39.207228824,-75.56996406 39.2074420320001,-75.5696300339999 39.2074420320001,-75.5696300339999 39.207228824,-75.56996406 39.207228824))'::geometry)" ``` -------------------------------- ### Filter Data by Attribute Source: https://github.com/geodan/pg2b3dm/blob/master/README.md Use the -q or --query parameter to filter data based on attribute values. This example selects features where the 'ogc_fid' attribute equals '118768'. ```bash -q "ogc_fid=118768" ``` -------------------------------- ### Specify Attribute Columns Source: https://context7.com/geodan/pg2b3dm/llms.txt Stores feature attributes in the 3D Tiles batch table or as EXT_Structural_Metadata. Multiple columns are comma-separated without spaces. Example SQL statements show how to add attribute columns to a table. ```sql -- Add attribute columns to the table ALTER TABLE buildings ADD COLUMN name VARCHAR NOT NULL DEFAULT 'unknown'; ALTER TABLE buildings ADD COLUMN build_year INTEGER; ALTER TABLE buildings ADD COLUMN tags VARCHAR[] DEFAULT '{residential, old}'; ``` -------------------------------- ### Build and Run pg2b3dm from Source Source: https://github.com/geodan/pg2b3dm/blob/master/src/release_notes_0.10.md Steps to clone the pg2b3dm repository, checkout the 'shaders' branch, build the project using dotnet, and run the application. This is for development and testing purposes. ```bash $ git clone https://github.com/Geodan/pg2b3dm.git $ git checkout shaders $ cd pg2b3dm/src $ dotnet build $ dotnet run ``` -------------------------------- ### Initialize Cesium Viewer and Load 3D Tileset Source: https://github.com/geodan/pg2b3dm/blob/master/sample_data/amsterdam/cesium/index.html Sets up the Cesium Ion access token, creates a Cesium Viewer with world terrain, and adds a 3D Tileset to the scene. It also configures the viewer to zoom to the tileset and enables depth testing against terrain. ```javascript Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNDc1ZjQwMS1hOGI2LTQyNmUtYmYxMi1jODlhNDNlMjViZTkiLCJpZCI6NDc4OSwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MTYyNTg3OX0.mNoGLdYuwqsnRRkQtdYNMbJfMBoZF2hPkbc4SRVVqNw'; var viewer = new Cesium.Viewer('cesiumContainer', { terrainProvider : Cesium.createWorldTerrain() }); viewer.scene.debugShowFramesPerSecond = true; var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ url : 'tileset.json' })); viewer.scene.globe.depthTestAgainstTerrain = true; viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0, -0.5, 0)); viewer.scene.primitives.add(tileset); ``` -------------------------------- ### Initialize Cesium Viewer and Load 3D Tileset Source: https://github.com/geodan/pg2b3dm/blob/master/sample_data/delaware/cesium/index.html Sets up the Cesium viewer with a default access token and loads a 3D Tileset. Debugging features for frames per second and bounding volumes are enabled. Use this for basic 3D Tiles visualization. ```javascript Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNDc1ZjQwMS1hOGI2LTQyNmUtYmYxMi1jODlhNDNlMjViZTkiLCJpZCI6NDc4OSwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MTYyNTg3OX0.mNoGLdYuwqsnRRkQtdYNMbJfMBoZF2hPkbc4SRVVqNw'; var viewer = new Cesium.Viewer('cesiumContainer', { // terrainProvider : Cesium.createWorldTerrain() }); viewer.scene.debugShowFramesPerSecond = true; var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ url : 'tileset.json' })); tileset.debugShowBoundingVolume = true; tileset.debugColorizeTiles = true; viewer.scene.globe.depthTestAgainstTerrain = true; viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0, -0.5, 0)); viewer.scene.primitives.add(tileset); ``` -------------------------------- ### Check PostGIS Projection Transformation Source: https://github.com/geodan/pg2b3dm/blob/master/getting_started.md Verifies the coordinate transformation from EPSG:7415 to EPSG:4979 in PostGIS. Ensure projection grids are installed for accurate vertical value conversion. ```sql select ST_AsText(ST_Transform(ST_GeomFromText('POINT(121302 487371 2.68)', 7415), 4979)); ``` -------------------------------- ### Specify Output Directory using -o Source: https://context7.com/geodan/pg2b3dm/llms.txt Sets the output directory to '/var/www/tiles/buildings'. The tool will create 'tileset.json', 'content/', and 'subtrees/' subdirectories within this path. ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings \ -o /var/www/tiles/buildings ``` -------------------------------- ### pg2b3dm Command Line Options Source: https://github.com/geodan/pg2b3dm/blob/master/README.md Lists all available command-line options for pg2b3dm. Note that database connection parameters are deprecated in favor of the --connection string. ```bash -U, --username [Deprecated] Database user. Use --connection instead. -h, --host [Deprecated] (Default: localhost) Database host. Use --connection instead. -d, --dbname [Deprecated] Database name. Use --connection instead. -c, --column (Default: geom) Geometry column -t, --table Required. Database table, include database schema if needed -p, --port [Deprecated] (Default: 5432) Database port. Use --connection instead. --connection (Default: '') Database connection string. Tip: for long-running queries, include CommandTimeOut=0. -o, --output (Default: output) Output path -a, --attributecolumns (Default: '') Attribute columns -q, --query (Default: '') Query parameter --copyright (Default: '') glTF asset copyright --default_color (Default: #FFFFFF) Default color, in RGB(A) order --default_metallic_roughness (Default: #008000) Default metallic roughness --double_sided (Default: true) Default double sided --default_alpha_mode (Default: OPAQUE) Default glTF material AlphaMode. Other values: BLEND and MASK. Defines how the alpha value is interpreted. --alpha_cutoff (Default: 0.5) Default glTF material AlphaCutoff (used with MASK alpha mode) --create_gltf (Default: true) Create glTF files --radiuscolumn (Default: '') Column with radius values for lines --max_features_per_tile (Default: 1000) maximum features per tile -l, --lodcolumn (Default: '') LOD column -g, --geometricerror (Default: 2000) Geometric error --geometricerrorfactor (Default: 2) Geometric error factor --shaderscolumn (Default: '') shaders column --tilesetVersion (Default: '') Tileset version --use_implicit_tiling (Default: true) use 1.1 implicit tiling --add_outlines (Default: false) Add outlines -r, --refinement (Default: ADD) Refinement ADD/REPLACE --skip_create_tiles (Default: false) Skip creating tiles --keep_projection (Default: false) Keep projection of input data --subdivision (Default: QUADTREE) Subdivision schema QUADTREE/OCTREE --help Display this help screen. --version Display version information. ``` -------------------------------- ### Show Subset of Buildings by Year in CesiumJS Source: https://github.com/geodan/pg2b3dm/blob/master/styling.md Filter the visibility of 3D Tiles based on an attribute query. This example shows buildings with 'bouwjaar' greater than 1975. ```javascript buildings.style.show = "${feature['bouwjaar']} > 1975" ``` -------------------------------- ### Initialize CesiumJS Viewer and Load 3D Tileset Source: https://github.com/geodan/pg2b3dm/blob/master/sample_data/3dbag/tienhoven/index.html Sets up the CesiumJS Ion access token and initializes a viewer. It then loads a 3D Tileset from a URL and adds it to the scene. Ensure the 'cesiumContainer' element exists in your HTML. ```javascript Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI0NWQyNjhiOC1jYmQ5LTQyZWQtODJlMi01MTg5ZDNkMzRhOGQiLCJpZCI6NDc4OSwiaWF0IjoxNzUzNzk1NzA1fQ.m2LCYXXGRYZPfwE3HG272TFz7xBIIwXj1wWNDXJ0V_w'; var viewer = new Cesium.Viewer('cesiumContainer', { //terrain: Cesium.Terrain.fromWorldTerrain(), }); var terrainProvider = await Cesium.CesiumTerrainProvider.fromUrl('https://3d.kadaster.nl/dtm/ahn4'); // viewer.scene.terrainProvider = terrainProvider; viewer.scene.globe.depthTestAgainstTerrain=true; viewer.scene.light = new Cesium.DirectionalLight({ direction: viewer.scene.camera.directionWC, }); viewer.scene.preRender.addEventListener(function (scene, time) { viewer.scene.light.direction = Cesium.Cartesian3.clone( viewer.scene.camera.directionWC, viewer.scene.light.direction ); }); //viewer.camera.flyTo({ // destination: Cesium.Cartesian3.fromDegrees(5.6481455, 51.9585143, 300.0), //}); const tileset = await Cesium.Cesium3DTileset.fromUrl( "tileset.json" ); viewer.scene.primitives.add(tileset); ``` -------------------------------- ### Clone pg2b3dm Repository and Build Source: https://github.com/geodan/pg2b3dm/blob/master/src/release_notes_0.9.md Steps to clone the pg2b3dm repository from GitHub, checkout a specific issue branch, navigate to the source directory, build the project using dotnet, and run the application. ```bash $ git clone https://github.com/Geodan/pg2b3dm.git $ git checkout issue_5_refine_replace $ cd pg2b3dm/src $ dotnet build $ dotnet run ``` -------------------------------- ### Basic Conversion: PostGIS Table to 3D Tiles Source: https://context7.com/geodan/pg2b3dm/llms.txt Performs a basic conversion from a PostGIS table to 3D Tiles. Requires a connection string and the source table name. Output files are generated in the ./output directory. ```bash # Minimal invocation — reads 'geom' column from 'buildings' table pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings # Output (default): ./output/tileset.json + ./output/content/*.glb + ./output/subtrees/*.subtree ``` -------------------------------- ### Connect to PostgreSQL Database Source: https://github.com/geodan/pg2b3dm/blob/master/dataprocessing/dataprocessing_citygml.md Opens a connection to the PostgreSQL database using the psql command-line client. ```bash psql -h localhost -p 5440 -U postgres -d postgres ``` -------------------------------- ### Configure Debugging in VS Code Source: https://github.com/geodan/pg2b3dm/blob/master/README.md Clone the repository and open the project in Visual Studio Code. Modify the 'args' in .vscode/launch.json to set the connection parameters for debugging. ```bash $ git clone https://github.com/Geodan/pg2b3dm.git $ cd src $ code . ``` -------------------------------- ### Run pg2b3dm from Source Source: https://github.com/geodan/pg2b3dm/blob/master/README.md Compile and run the pg2b3dm application directly from the source code using the .NET 8.0 SDK. This requires cloning the repository and navigating to the source directory. ```bash $ git clone https://github.com/Geodan/pg2b3dm.git $ cd pg2b3dm/src/pg2b3dm $ dotnet run -- --connection "Host=my_host;Username=my_user;Database=my_database;CommandTimeOut=0" -t my_schema.my_table ``` -------------------------------- ### Add and Update Shader Column in SQL Source: https://github.com/geodan/pg2b3dm/blob/master/styling.md Demonstrates how to add a JSON column for shaders and update it with PbrMetallicRoughness shader details in SQL. ```sql ALTER TABLE mytable ADD COLUMN simple_shader json; update mytable set simple_shader = '{ "PbrMetallicRoughness": { "BaseColors": ["#008000", "#008000"] } }'; ``` -------------------------------- ### Load and Add 3D Tileset Source: https://github.com/geodan/pg2b3dm/blob/master/sample_data/3dbag/sibbe/index.html Asynchronously loads a 3D Tileset from a local URL and adds it to the scene. Includes a zoom to the tileset. ```javascript const tileset = await Cesium.Cesium3DTileset.fromUrl( "./1.1/tileset.json" ); viewer.scene.primitives.add(tileset); // tileset.debugShowBoundingVolume = true; // Uncomment for debugging // tileset.debugColorizeTiles = true; // Uncomment for debugging viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0, -0.5, 0)); ``` -------------------------------- ### End-to-End: Dutch 3D BAG Buildings to 3D Tiles Source: https://context7.com/geodan/pg2b3dm/llms.txt A complete workflow for converting Dutch 3D BAG building data from GeoPackage to 3D Tiles. This includes setting up PostGIS, importing data, creating a spatial index, and running the pg2b3dm conversion with attribute export. ```bash # 1. Start PostGIS docker run -it -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e PROJ_NETWORK=ON \ postgis/postgis:18-3.6 # 2. Download Sibbe village GeoPackage from 3DBAG # https://3dbag.nl/nl/download?tid=8-688-40 → 8-688-40.gpkg # 3. Import into PostGIS ogr2ogr -f PostgreSQL pg:"host=localhost user=postgres password=postgres" \ 8-688-40.gpkg lod22_3d -nln sibbe # 4. Create spatial index psql -h localhost -U postgres -d postgres \ -c "CREATE INDEX ON sibbe USING gist(st_centroid(st_envelope(geom)))" # 5. Convert to 3D Tiles with attribute export pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=postgres;CommandTimeOut=0" \ -c geom \ -t sibbe \ -a identificatie ``` -------------------------------- ### Build pg2b3dm Docker Image Source: https://github.com/geodan/pg2b3dm/blob/master/README.md Clone the repository and build the Docker image locally. This command is used for both regular builds and for building images for specific feature branches. ```bash $ git clone https://github.com/Geodan/pg2b3dm.git $ cd pg2b3dm/src $ docker build -t geodan/pg2b3dm . ``` ```bash $ git clone https://github.com/Geodan/pg2b3dm.git $ git checkout {name_of_feature_branch} $ cd pg2b3dm/src $ docker build -t geodan/pg2b3dm:{name_of_feature_branch} . ``` -------------------------------- ### Run pg2b3dm from Docker Source: https://github.com/geodan/pg2b3dm/blob/master/README.md Execute the pg2b3dm Docker container, mounting a local directory for output. Ensure the connection string and table name are correctly specified. ```bash $ docker run -v $(pwd)/output:/app/output -it geodan/pg2b3dm --connection "Host=my_host;Username=my_user;Database=my_database;CommandTimeOut=0" -t my_schema.my_table ``` -------------------------------- ### Run pg2b3dm using Docker Source: https://github.com/geodan/pg2b3dm/blob/master/README.md Commands to pull the latest Docker image and run the pg2b3dm container. ```bash $ docker pull geodan/pg2b3dm $ docker run geodan/pg2b3dm ``` -------------------------------- ### Generate 3D Tiles with LOD Source: https://github.com/geodan/pg2b3dm/blob/master/cesium_notes.md Use this command to generate 3D Tiles with Level of Detail (LOD) support. Ensure the --lodcolumn parameter is not empty and the database table contains LOD values. LOD is not available when implicit tiling is used. ```bash pg2b3dm --connection "Host=localhost;Port=5432;Username=postgres;Database=postgres;CommandTimeOut=0" -c geom_triangle -t delaware_buildings_lod -g 2000 --shaderscolumn shaders --lodcolumn lodcolumn --use_implicit_tiling false -r REPLACE --geometricerrorfactor 8 ``` -------------------------------- ### Initialize Cesium Viewer with PDOK Imagery Source: https://github.com/geodan/pg2b3dm/blob/master/sample_data/3dbag/sibbe/index.html Sets up a Cesium viewer with custom PDOK aerial imagery as the base layer. Disables default credits and sets the globe to white. ```javascript var viewer = new Cesium.Viewer('cesiumContainer', { requestRenderMode : true, animation: false, baseLayerPicker: false, fullscreenButton: true, vrButton: false, geocoder: true, homeButton: false, infoBox: true, selectionIndicator: true, timeline: false, shadows: false, navigationHelpButton: false, navigationInstructionsInitiallyVisible: true, scene3DOnly: true, geocoder: false, shouldAnimate: true, baseLayer: new Cesium.ImageryLayer(new Cesium.UrlTemplateImageryProvider({ url: "https://service.pdok.nl/hwh/luchtfotorgb/wmts/v1_0/2024_ortho25/EPSG:3857/{z}/{x}/{y}.jpeg", maximumLevel: 19, })) }); viewer.cesiumWidget.creditContainer.style.display = "none"; viewer.scene.globe.baseColor = Cesium.Color.WHITE; ``` -------------------------------- ### Enable LOD Support with Explicit Tiling Source: https://context7.com/geodan/pg2b3dm/llms.txt Enables Level of Detail (LOD) support using an explicit tiling strategy. Requires a PostGIS table with an integer LOD column. Ensure 'use_implicit_tiling' is set to false. ```sql -- Prepare LOD column in PostGIS ALTER TABLE buildings ADD COLUMN lod INTEGER; UPDATE buildings SET lod = 0 WHERE simplified = true; UPDATE buildings SET lod = 1 WHERE simplified = false; ``` ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings \ -l lod \ --use_implicit_tiling false \ -r REPLACE \ -g 2000 \ --geometricerrorfactor 8 ``` -------------------------------- ### Configure Scene Lighting and Render Mode Source: https://github.com/geodan/pg2b3dm/blob/master/sample_data/3dbag/sibbe/index.html Sets up a directional light following the camera and configures the globe's lighting and depth testing. Disables high dynamic range rendering. ```javascript viewer.scene.light = new Cesium.DirectionalLight({ direction: viewer.scene.camera.directionWC, }); viewer.scene.preRender.addEventListener(function (scene, time) { viewer.scene.light.direction = Cesium.Cartesian3.clone( viewer.scene.camera.directionWC, viewer.scene.light.direction ); }); viewer.scene.globe.depthTestAgainstTerrain = true; viewer.scene.globe.enableLighting = false; viewer.scene.highDynamicRange = false; ``` -------------------------------- ### Import CityGML Data using citydb tool Source: https://github.com/geodan/pg2b3dm/blob/master/dataprocessing/dataprocessing_citygml.md Imports a CityGML file into the 3DCityDB PostgreSQL database using the 'citydb import' command-line tool. ```bash citydb import citygml -H localhost -d postgres -u postgres -p postgres --db-port 5440 den_haag_3d_archipelbuurt.gml ``` -------------------------------- ### Configure Terrain and Lighting Source: https://github.com/geodan/pg2b3dm/blob/master/sample_data/3dbag/tienhoven/index.html Configures the terrain provider, enables depth testing against terrain, and sets up a directional light that follows the camera. This enhances the visual representation of the 3D scene. ```javascript var terrainProvider = await Cesium.CesiumTerrainProvider.fromUrl('https://3d.kadaster.nl/dtm/ahn4'); // viewer.scene.terrainProvider = terrainProvider; viewer.scene.globe.depthTestAgainstTerrain=true; tileset.debugShowBoundingVolume = true; // tileset.debugColorizeTiles = true; viewer.scene.globe.depthTestAgainstTerrain = true; viewer.scene.globe.enableLighting = false; viewer.scene.highDynamicRange = false; viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0, -0.5, 0)); ``` -------------------------------- ### Run pg2b3dm 0.9.4 Docker Container Source: https://github.com/geodan/pg2b3dm/blob/master/src/release_notes_0.9.md Execute this command to run the pg2b3dm version 0.9.4 Docker container. The output shows the tool version and copyright information. ```bash $ docker run geodan/pg2b3dm:0.9.4 tool: pg2b3dm 0.9.4.0 pg2b3dm 0.9.4 Copyright (C) 2020 pg2b3dm ``` -------------------------------- ### Advanced: Per-Class Shader Coloring View Source: https://context7.com/geodan/pg2b3dm/llms.txt Define a SQL view for advanced per-class shader coloring using PBR material properties. This view can then be used in the pg2b3dm conversion. ```sql -- Advanced: per-class shader coloring via a view CREATE OR REPLACE VIEW citydb.geoms4tiles AS WITH material_data_cte AS ( SELECT classname, JSON_OBJECT( 'PbrMetallicRoughness': JSON_OBJECT( 'BaseColors': ARRAY[pbr_metallic_roughness_base_color] ABSENT ON NULL RETURNING json ) ABSENT ON NULL RETURNING json ) AS material_data FROM materials_for_features ) SELECT ftr.objectid, obcl.classname, pbr.material_data, geometry AS geom FROM geometry_data gmdt LEFT JOIN feature ftr ON ftr.id = gmdt.feature_id LEFT JOIN objectclass obcl ON obcl.id = ftr.objectclass_id LEFT JOIN namespace ns ON ns.id = obcl.namespace_id LEFT JOIN material_data_cte pbr ON pbr.classname = obcl.classname WHERE ftr.objectid NOT LIKE 'bag%'; ``` -------------------------------- ### Run pg2b3dm via Docker Source: https://context7.com/geodan/pg2b3dm/llms.txt Runs pg2b3dm using a Docker container. Mounts a local directory for output and specifies database connection details and the target table. ```bash docker pull geodan/pg2b3dm docker run -v $(pwd)/output:/app/output -it geodan/pg2b3dm \ --connection "Host=my_host;Username=my_user;Database=my_db;CommandTimeOut=0" \ -t my_schema.my_table ``` -------------------------------- ### Load 3D Tileset in CesiumJS Source: https://context7.com/geodan/pg2b3dm/llms.txt This snippet demonstrates how to load a 3D Tileset from a URL and add it to a CesiumJS viewer. Ensure the CesiumJS library is included and a 'cesiumContainer' element exists in your HTML. ```javascript const viewer = new Cesium.Viewer('cesiumContainer'); const tileset = await Cesium.Cesium3DTileset.fromUrl("output/tileset.json"); viewer.scene.primitives.add(tileset); viewer.zoomTo(tileset); ``` -------------------------------- ### Enable Cesium Building Outlines Source: https://context7.com/geodan/pg2b3dm/llms.txt Set `--add_outlines true` to include the `CESIUM_primitive_outline` glTF extension, which enables edge rendering for buildings in CesiumJS. ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings \ --add_outlines true ``` -------------------------------- ### Apply Shaders Column with pg2b3dm Source: https://context7.com/geodan/pg2b3dm/llms.txt This command applies the PBR shader definitions from the `simple_shader` column to the generated 3D Tiles. ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings \ --shaderscolumn simple_shader ``` -------------------------------- ### Docker Pull and Run Command Source: https://github.com/geodan/pg2b3dm/blob/master/src/release_notes_0.10.md Command to pull the pg2b3dm Docker image version 0.10.0_preview1 and run it. This is useful for testing the release. ```bash $ docker pull geodan/pg2b3dm:0.10.0_preview1 $ docker run geodan/pg2b3dm:0.10.0_preview1 tool: pg2b3dm 0.10.0.0 pg2b3dm 0.10.0 Copyright (C) 2020 pg2b3dm ``` -------------------------------- ### Apply BLEND Alpha Mode with Shaders Source: https://context7.com/geodan/pg2b3dm/llms.txt This command generates 3D Tiles with semi-transparent surfaces by combining `--shaderscolumn` with `--default_alpha_mode BLEND`. ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.towns \ -c geom \ --shaderscolumn simple_shader \ --default_alpha_mode BLEND ``` -------------------------------- ### Style Each Triangle Individually (Server-Side) Source: https://github.com/geodan/pg2b3dm/blob/master/styling.md Apply a unique shader to every triangle in a mesh. This requires knowing the total number of triangles in advance and providing a shader for each. ```json { "PbrMetallicRoughness": { "BaseColors": [ "#008000", "#FF0000", "#EEC900", "#EEC900" ] } } ``` -------------------------------- ### Create Recommended Spatial Index Source: https://context7.com/geodan/pg2b3dm/llms.txt Create a spatial index on the geometry column for improved performance with large tables. Verify its existence using a SELECT query. ```sql -- Recommended spatial index CREATE INDEX ON my_table USING gist(st_centroid(st_envelope(geom))); -- Verify index exists SELECT indexname FROM pg_indexes WHERE tablename = 'my_table'; ``` -------------------------------- ### Generate 3D Tiles with Blend Alpha Mode Source: https://github.com/geodan/pg2b3dm/blob/master/styling.md Command-line usage of pg2b3dm to generate 3D Tiles from a 'towns' table, specifying the shader column and setting the default alpha mode to BLEND. ```bash pg2b3dm --connection "Host=localhost;Username=postgres;Database=postgres;CommandTimeOut=0" -t towns -c geom --shaderscolumn simple_shader --default_alpha_mode BLEND ``` -------------------------------- ### Basic pg2b3dm Conversion Source: https://context7.com/geodan/pg2b3dm/llms.txt Perform a basic conversion of PostGIS data to 3D Tiles. Ensure a spatial index is present on the geometry column for performance. ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings_lod \ -l lodcolumn \ --use_implicit_tiling false \ -r REPLACE ``` -------------------------------- ### Enable Implicit Tiling for CesiumJS Source: https://context7.com/geodan/pg2b3dm/llms.txt Enables 3D Tiles 1.1 implicit tiling, generating subtree files and a compact tileset.json. This is the default behavior and is recommended for CesiumJS. ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings \ --use_implicit_tiling true ``` -------------------------------- ### Create Polygon Table with Transparent Color Source: https://github.com/geodan/pg2b3dm/blob/master/styling.md SQL statements to create a polygon table and insert a polygon with a 50% transparent green color. ```sql CREATE TABLE towns ( id SERIAL PRIMARY KEY, name TEXT, geom GEOMETRY(POLYGONZ, 28992) ); INSERT INTO towns (name, geom) VALUES ( 'amsterdam', ST_GeomFromText( 'POLYGONZ(( 114198.8883 485033.8681 10, 129120.3625 485033.8681 10, 129120.3625 492341.7244 10, 114198.8883 492341.7244 10, 114198.8883 485033.8681 10 ))', 28992 ) ); ALTER TABLE towns ADD COLUMN simple_shader json; update towns set simple_shader = '{ "PbrMetallicRoughness": { "BaseColors": ["#00FF0080"] } }'; ``` -------------------------------- ### Import GeoPackage into PostGIS using ogr2ogr Source: https://github.com/geodan/pg2b3dm/blob/master/getting_started.md Imports a GeoPackage file into a PostgreSQL database. Specify the host, user, and the target table name. ```bash $ ogr2ogr -f PostgreSQL pg:"host=localhost user=postgres" 8-688-40.gpkg lod22_3d -nln sibbe ``` -------------------------------- ### Import CSV data into materials_for_features Source: https://github.com/geodan/pg2b3dm/blob/master/dataprocessing/dataprocessing_citygml.md Loads material mapping data from a CSV file into the 'materials_for_features' table. Ensure the CSV file has a header row matching the table columns. ```sql \copy materials_for_features FROM 'materials_for_features.csv' WITH (FORMAT csv, HEADER true); ``` -------------------------------- ### Generate Tileset JSON Only Source: https://context7.com/geodan/pg2b3dm/llms.txt Use `--skip_create_tiles true` to generate only the `tileset.json` file without writing individual tile content files. This is useful for previewing the tiling structure. ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings \ --skip_create_tiles true ``` -------------------------------- ### 3DCityDB v5 CityGML Import and Conversion Source: https://context7.com/geodan/pg2b3dm/llms.txt Import CityGML data into a 3DCityDB v5 PostgreSQL database and convert it to 3D Tiles. Textures are automatically applied per tile. ```bash # 1. Start 3DCityDB v5 in Docker docker run -d -p 5440:5432 -e POSTGRES_PASSWORD=postgres -e PROJ_NETWORK=ON -e SRID=7415 \ 3dcitydb/3dcitydb-pg # 2. Import CityGML citydb import citygml -H localhost -d postgres -u postgres -p postgres --db-port 5440 \ den_haag_3d_archipelbuurt.gml # 3. Create spatial index psql -h localhost -p 5440 -U postgres -d postgres \ -c "CREATE INDEX ON citydb.geometry_data USING gist(st_centroid(st_envelope(geometry)))" # 4. Convert to 3D Tiles (textures applied automatically) pg2b3dm \ --connection "Host=localhost;Port=5440;Username=postgres;Database=postgres;CommandTimeOut=0" \ -t citydb.geometry_data \ -c geometry \ --attributecolumns geometry_properties ``` -------------------------------- ### Add 3D Tileset to CesiumJS Viewer Source: https://github.com/geodan/pg2b3dm/blob/master/getting_started.md Loads a generated 3D Tileset from a URL and adds it to the CesiumJS scene. Ensure the 'tileset.json' path is correct. ```javascript const tileset = await Cesium.Cesium3DTileset.fromUrl( "tileset.json" ); viewer.scene.primitives.add(tileset); ``` -------------------------------- ### Use QUADTREE Subdivision for Buildings Source: https://context7.com/geodan/pg2b3dm/llms.txt Configures the tiling subdivision strategy to QUADTREE, which is recommended for flat datasets like cities and buildings. This is the default setting. ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings \ --subdivision QUADTREE ``` -------------------------------- ### Apply Radius Column with Shaders Source: https://context7.com/geodan/pg2b3dm/llms.txt This command generates 3D Tiles for line geometries, using a specified column for tube radius and another for shaders. ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.pipes \ -c geom \ --radiuscolumn radius \ --shaderscolumn pipe_shader ``` -------------------------------- ### Apply MASK Alpha Mode with Alpha Cutoff Source: https://context7.com/geodan/pg2b3dm/llms.txt Use `--default_alpha_mode MASK` and `--alpha_cutoff` for binary transparency, where surfaces are either fully opaque or fully transparent based on the cutoff value. ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings \ --default_alpha_mode MASK \ --alpha_cutoff 0.5 ``` -------------------------------- ### Export 3D Tiles with shaders Source: https://github.com/geodan/pg2b3dm/blob/master/dataprocessing/dataprocessing_citygml.md Generates 3D Tiles from the 'citydb.geoms4tiles' view, applying custom colors defined in the 'material_data' column using the '--shaderscolumn' parameter. It also includes objectid and classname as attributes. ```bash pg2b3dm --connection "Host=localhost;Port=5440;Username=postgres;Database=postgres;CommandTimeOut=0" -t citydb.geoms4tiles -c geom --shaderscolumn material_data -a objectid,classname ``` -------------------------------- ### Explicit Database Connection String Source: https://context7.com/geodan/pg2b3dm/llms.txt Specifies an explicit database connection string for pg2b3dm. Use 'CommandTimeOut=0' for large datasets to prevent query timeouts. ```bash # Explicit connection string pg2b3dm \ --connection "Host=db.example.com;Port=5432;Username=gisuser;Database=geodata;Ssl Mode=Require;CommandTimeOut=0" \ -t public.buildings ``` ```bash # Password is read interactively unless PGPASSWORD env var is set or trusted auth is used export PGPASSWORD=mysecretpassword pg2b3dm --connection "Host=localhost;Username=postgres;Database=mydb" -t buildings ``` -------------------------------- ### Generate Mapbox GL JS v3 Tiles Source: https://context7.com/geodan/pg2b3dm/llms.txt Generate 3D Tiles in Mapbox GL JS v3 format. This format is experimental and may require specific configurations. ```bash # Generate tiles in Mapbox format pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings \ --format Mapbox ``` -------------------------------- ### Apply Single Shader to All Triangles (Server-Side) Source: https://github.com/geodan/pg2b3dm/blob/master/styling.md Use a single color to style all triangles in a geometry when using server-side styling. This is applied via a JSON document in a database column. ```sql update delaware_buildings set simple_shader = '{ "PbrMetallicRoughness": { "BaseColors": ["#ff0000"] } }'; ``` -------------------------------- ### Set Default Base Color and Metallic Roughness Source: https://context7.com/geodan/pg2b3dm/llms.txt Use `--default_color` and `--default_metallic_roughness` to specify fallback PBR material properties for features lacking a shaders column entry. ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings \ --default_color "#ADD8E6" \ --default_metallic_roughness "#004080" ``` -------------------------------- ### Convert PostGIS Data to 3D Tiles with pg2b3dm Source: https://github.com/geodan/pg2b3dm/blob/master/getting_started.md Converts data from a PostGIS table to 3D Tiles format. Requires connection details, the geometry column, the table name, and attributes to include. ```bash $ pg2b3dm --connection "Host=localhost;Username=postgres;Database=postgres;CommandTimeOut=0" -c geom -t sibbe -a identificatie ``` -------------------------------- ### Export Buildings with Multiple Attribute Columns Source: https://context7.com/geodan/pg2b3dm/llms.txt Exports building data, including 'name', 'build_year', and 'tags' attributes. Ensure these columns exist in your PostgreSQL table. ```bash pg2b3dm \ --connection "Host=localhost;Username=postgres;Database=mydb;CommandTimeOut=0" \ -t public.buildings \ -a name,build_year,tags ``` -------------------------------- ### Create view for geometry and material data Source: https://github.com/geodan/pg2b3dm/blob/master/dataprocessing/dataprocessing_citygml.md Generates a view that joins geometry data with CityGML object class information and applies material colors based on the 'materials_for_features' table. It filters out specific building parts and can optionally exclude linestrings. ```sql CREATE OR REPLACE VIEW citydb.geoms4tiles AS WITH material_data_cte AS ( SELECT mtf.namespace_of_classname, mtf.classname, JSON_OBJECT( 'PbrMetallicRoughness' : JSON_OBJECT( 'BaseColors' : NULLIF( ARRAY[mtf.pbr_metallic_roughness_base_color], '{NULL}'::text[] ), 'MetallicRoughness' : NULLIF( ARRAY[mtf.pbr_metallic_roughness_metallic_roughness], '{NULL}'::text[] ) ABSENT ON NULL RETURNING json ) ABSENT ON NULL RETURNING json ) AS material_data FROM materials_for_features mtf ) SELECT ftr.objectid, obcl.classname, pbr.material_data, geometry AS geom FROM geometry_data gmdt LEFT JOIN feature ftr ON ftr.id = gmdt.feature_id LEFT JOIN objectclass obcl ON obcl.id = ftr.objectclass_id LEFT JOIN namespace ns ON ns.id = obcl.namespace_id LEFT JOIN material_data_cte pbr ON pbr.namespace_of_classname = ns.alias AND pbr.classname = obcl.classname where ftr.objectid NOT LIKE 'bag%'; ``` -------------------------------- ### Convert using Per-Class Shader View Source: https://context7.com/geodan/pg2b3dm/llms.txt Convert data to 3D Tiles using the previously defined per-class shader view. The `--shaderscolumn` option specifies the column containing the material data. ```bash # Convert using the per-class shader view pg2b3dm \ --connection "Host=localhost;Port=5440;Username=postgres;Database=postgres;CommandTimeOut=0" \ -t citydb.geoms4tiles \ -c geom \ --shaderscolumn material_data \ -a objectid,classname ``` -------------------------------- ### Convert CityGML to 3D Tiles with pg2b3dm Source: https://github.com/geodan/pg2b3dm/blob/master/dataprocessing/dataprocessing_citygml.md Converts imported CityGML data into 3D Tiles format using the pg2b3dm tool, specifying database connection and relevant columns. ```bash pg2b3dm --connection "Host=localhost;Port=5440;Username=postgres;Database=postgres;CommandTimeOut=0" -t citydb.geometry_data -c geometry --attributecolumns geometry_properties ``` -------------------------------- ### Create materials_for_features table Source: https://github.com/geodan/pg2b3dm/blob/master/dataprocessing/dataprocessing_citygml.md Defines the schema for storing material mappings between CityGML classes and PBR properties. This table is used to assign custom colors to different CityGML feature types. ```sql CREATE TABLE citydb.materials_for_features ( namespace_of_classname TEXT, classname TEXT, pbr_metallic_roughness_base_color TEXT, pbr_metallic_roughness_metallic_roughness TEXT ); ```