Py3DTilers is a Python tool and library allowing to build 3D Tiles
tilesets out of various geometrical formats e.g. OBJ, GeoJSON, IFC or CityGML through 3dCityDB databases.
Py3DTilers uses py3dtiles
python library (forked from Oslandia's py3dtiles) for its in memory representation of tilesets.
Py3DTilers can only produce Batched 3D Models (B3DM)
. If you want to produce Point Clouds (PNTS)
, see Oslandia's py3dtiles CLI.
An article that present the tool is available in the ISPRS annals here.
Find 3D Tiles created with Py3DTilers in this online demo.
- Common features: features shared by all tilers
- ObjTiler: converts OBJ files to a 3D Tiles tileset
- GeojsonTiler: converts GeoJson files to a 3D Tiles tileset
- IfcTiler: converts IFC files to a 3D Tiles tileset
- CityTiler: converts CityGML features (e.g buildings, water bodies, terrain...) extracted from a 3dCityDB database to a 3D Tiles tileset
- TilesetReader: read, merge or transform 3DTiles tilesets
Py3DTilers works with Python 3.9.
You can use a lower version if you don't plan to work with the IfcTiler. Then, comment the line of the IfcOpenShell in the setup.py.
Install binary sub-dependencies with your platform package installer e.g. for Ubuntu use
apt-get install -y libpq-dev # required usage of psycopg2 within py3dtilers
apt-get install python3.9 # Python3 version must be 3.9
Install Py3DTilers in a safe python virtual environment (not mandatory yet quite recommended)
apt-get install virtualenv git
git clone https://github.com/VCityTeam/py3dtilers
cd py3dtilers
virtualenv -p python3.9 venv
. venv/bin/activate
(venv)$ pip install -e .
Install python3.9.
In order to install Py3DTilers from sources use:
git clone https://github.com/VCityTeam/py3dtilers
cd py3dtilers
python3.9 -m venv venv
. venv/Scripts/activate
(venv)$ pip install -e .
In order to access to the different flavors of tilers, refer to the corresponding readmes to discover their respective usage and features:
- Common features readme
- CityTiler readme
- GeojsonTiler readme
- ObjTiler readme
- IfcTiler readme
- TilesetReader readme
Useful tutorials:
- CityTiler usage example
- GeojsonTiler usage example
- Visualize 3DTiles in Cesium, iTowns or UD-Viz
- Create 3DTiles from OpenStreetMap data
- Host CityGML data in 3DCityDB
After the installation, if you additionally wish to run unit tests, use
(venv)$ pip install -e .[dev,prod]
(venv)$ pytest
To run CityTiler's tests, you need to install PostgreSQL and Postgis.
To setup PostgreSQL with Postgis on Windows, follow the first step (1. Download PostgreSQL/PostGIS) of 3DCityDB tutorial.
For Ubuntu, follow this tutorial.
First, install the additional dev requirements
(venv)$ pip install -e .[dev]
To check if the code follows the coding style, run flake8
(venv)$ flake8 .
You can fix most of the coding style errors with autopep8
(venv)$ autopep8 --in-place --recursive py3dtilers/
If you want to apply autopep8
from root directory, exclude the venv directory
(venv)$ autopep8 --in-place --exclude='venv*' --recursive .
By default, the Py3DTilers' setup.py
build stage uses github's version of py3dtiles (as opposed to using Oslandia's version on Pypi.
When developing one might need/wish to use a local version of py3dtiles (located on host in another directory e.g. by cloning the original repository) it is possible
- to first install py3dtiles by following the installation notes
- then within the Py3DTilers (cloned) directory, comment out (or delete) the line reference to py3dtiles.
This boils down to :
$ git clone https://github.com/VCityTeam/py3dtiles
$ cd py3dtiles
$ ...
$ source venv/bin/activate
(venv)$ cd ..
(venv)$ git clone https://github.com/VCityTeam/py3dtilers
(venv)$ cd py3dtilers
(venv)$ # Edit setup.py and comment out py3dtiles reference
(venv)$ pip install -e .
(venv)$ pytest
- For developers, some design notes
- Credentials: CityTiler original code is due to Jeremy Gaillard (when working at LIRIS, University of Lyon, France)
When configuring your IDE to run a specific tiler, you must indicate the module you want to run (e.g. py3dtilers.CityTiler.CityTiler) and not the path to the file (i.e. not ${workspace_root}/py3dtilers/CityTiler/CityTiler.py), otherwise python will not be able to resolve the relative import of the Tilers to the Common package of Py3DTilers. An example of launch configuration in VSCode:
{
"version": "0.2.0",
"configurations": [
{
"name": "<launch_config_name>", // e.g. "CityTiler" or "bozo"
"type": "python",
"request": "launch",
"module": "<tiler_module>", // e.g. py3dtilers.CityTiler.CityTiler
"args": [
"--db_config_path",
"${workspaceRoot}/py3dtilers/CityTiler/<my_config_file.yml>"
],
"console": "integratedTerminal"
}
]
}
Python standard module cProfile allows to profile Python code.
Import modules:
import cProfile
import pstats
Profile the code between enable()
and disable()
:
cp = cProfile.Profile()
cp.enable() # Start profiling
# code here
cp.disable() # Stop profiling
p = pstats.Stats(cp)
p.sort_stats('tottime').print_stats() # Sort stats by time and print them
cProfile can be run in the shell with:
python -m cProfile script.py