tudelft3d / CityGML2OBJs

An experimental utility to convert CityGML data to OBJ, featuring decoupling of objects and conversion of attributes to colours
MIT License
94 stars 25 forks source link

IMPORTANT!!!

This project will not be further developed and bugs won't be fixed.

Instead, we advice you to use CityJSON (and convert your files with citygml-tools) and then use cjio export operator to get an OBJ file.


CityGML2OBJs

CityGML2OBJs-header-image

A robust semantic-aware utility to convert CityGML data to OBJ, featuring some additional options reflected through the suffix "s" in the name of the package:

Things to know

This is an experimental research software prototype. Therefore, support is limited, and the software is not without bugs. For instance, there are reports of crashes with large data sets and/or with invalid geometries.

If you'd like to learn more about OBJ, I recommend to read the Wikipedia entry and/or the specifications.

Publication and conditions for use

This software is free to use. You are kindly asked to acknowledge its use by citing it in a research paper you are writing, reports, and/or other applicable materials. If you used it for making a nice publication, please cite the following paper:

Biljecki, F., & Arroyo Ohori, K. (2015). Automatic semantic-preserving conversion between OBJ and CityGML. Eurographics Workshop on Urban Data Modelling and Visualisation 2015, pp. 25-30.

[PDF] [DOI]

@inproceedings{Biljecki:2015vk,
author = {Biljecki, Filip and Arroyo Ohori, Ken},
title = {{Automatic Semantic-preserving Conversion Between OBJ and CityGML}},
booktitle = {Eurographics Workshop on Urban Data Modelling and Visualisation 2015},
year = {2015},
pages = {25--30},
address = {Delft, Netherlands},
doi = {10.2312/udmv.20151345},
month = nov
}

Features explained in more details

System requirements

Python packages:

Optional:

OS and Python version

The software has been developed on Mac OSX in Python 2.7, and has not been tested with other configurations. Hence, it is possible that some of the functions will not work on Windows and on Python 3.

CityGML requirements

Mandatory:

Optional, but recommended:

About the validity of CityGML files

There have been reports that the code crashes for some CityGML files. Unfortunately, in some cases the triangulation code halts with a peculiar error as it encounters a weird geometry, that cannot be skipped (excepted). If your files won't convert, there's a chance that you have invalid CityGML files (albeit a CityGML2OBJs bug is not excluded). Please ensure that your files are valid. Alternatively, you can invoke the option -v 1 to skip such geometries--sometimes it works.

Hugo Ledoux built val3dity, a thorough GML validator which is available for free through a web interface. Use this tool to test your files.

Usage and options

Introduction

To simply convert CityGML data into OBJ type the following command:

python CityGML2OBJs.py -i /path/to/CityGML/files/ -o /path/to/new/OBJ/files/

The tool will convert all CityGML files it finds in that folder. The command works also with relative paths.

Semantics

If you call the -s 1 option:

python CityGML2OBJs.py -i /path/to/CityGML/files/ -o /path/to/new/OBJ/files/ -s 1

the tool will create an OBJ file for each of the boundary surfaces it encounters, e.g. Delft.gml containing RoofSurface, WallSurface and GroundSurface will result in: Delft-RoofSurface.obj, and so on.

Here is an example of the OBJ file representing the WallSurface:

Triangulated WallSurface

Regardless of the semantic option, the program always outputs the plain OBJ. This is a useful approach if you load data which does not have boundary surfaces (e.g. only a bunch of solids) so you'll always get something back. The tool detects if there are no thematic boundaries, so doesn't write empty OBJ files, for instance, an empty *-Window.obj for an LOD2 model.

Validate geometries

Call the -v 1 option:

python CityGML2OBJs.py -i /path/to/CityGML/files/ -o /path/to/new/OBJ/files/ -v 1

in order to validate the geometries and skip invalid ones. The tool will report invalid geometries with their <gml:id>.

Objects

CityGML is a structured format. If you call the flag -g 1 you'll preserve the objects in the OBJ file

python CityGML2OBJs.py -i /path/to/CityGML/files/ -o /path/to/new/OBJ/files/ -g 1

For the object option the name of the object will be derived from the <gml:id>, if not, an ordered list will be made starting from 1, and each object will be named as an integer from 1 to n, where n is the number of objects.

So this

<cityObjectMember>
   <bldg:Building gml:id="ab76da5b-82d6-44ad-a670-c1f8b4f00edc">
      <bldg:boundedBy>
         <bldg:GroundSurface>
            ...

becomes

o ab76da5b-82d6-44ad-a670-c1f8b4f00edc
f 635 636 637 
f 636 635 638 
f 639 640 641
...

Conversion of coordinates

Normally CityGML data sets are geo-referenced. This may be a problem for some software packages. Invoke -t 1 to convert the data set to a local system. The origin of the local system correspond to the point with the smallest coordinates (usually the one closest to south-west).

Skip the triangulation

OBJ supports polygons, but most software packages prefer triangles. Hence the polygons are triangulated by default (another reason is that OBJ doesn't support polys with holes). However, this may cause problems in some instances, or you might prefer to preserve polygons. If so, put -p 1 to skip the triangulation. Sometimes it also helps to bypass invalid geometries in CityGML data sets.

Known limitations

Colour attributes

Please note that this is an experimental feature adapted to specific settings.

I have CityGML files with the attribute value of the solar potential (derived with Solar3Dcity, an experimental tool that I have recently developed and release soon) for each polygon. Normally these values cannot be visualised and are lost in the conversion to other formats. This tool solves this problem by normalising the quantitative attributes and colour them according to a colorbar, which is stored as a material (MTL) file.

Ancillary tools have been developed to make this feature use-friendly and visually appealing. Open each of these ancillary python files and fiddle with the values.

Generate the MTL library:

python generateMTL.py

Print a colorbar with the transparent background:

python plotcolorbar.py

Put the newly generated MTL in the directory with the CityGML data and run the utility with the option -s 1 or -s 2 or -s 3:

python CityGML2OBJs.py -i /path/to/CityGML/files/ -o /path/to/new/OBJ/files/ -s 1

Now the values of the solar potential of roof surfaces in the CityGML file are stored as textures (colours), and such can be easily visualised:

solar3dcity-header

The different options are for transfering the values of attributes between different hierarchical levels. For instance, the option 3 takes the attribute assigned to the building, and colours only the triangles representing the RoofSurface, instead of all faces representing that building. If you want to discuss this in further details to accommodate your needs, do not hesitate to contact me.

Attributes

Performance

The speed mainly depends on the invoked options and the level of detail of the data which substantially increases the number of triangles in the OBJ, mostly due to the openings.

For benchmarking, I have tested the tool with a CityGML data set of 100 buildings, and the performance is as follows:

LOD0 and LOD1 have roughly the same performance as LOD2. Validation of polygons does not notably decrease the speed.

Contact for questions and feedback

Filip Biljecki

3D Geoinformation Research Group

Faculty of Architecture and the Built Environment

Delft University of Technology

email: fbiljecki at gmail dot com

Personal webpage

Acknowledgments

My colleagues: