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

Unable to convert Lyon or Rotterdam CityGML models to OBJ (possibly others too) #2

Closed robhawkes closed 8 years ago

robhawkes commented 9 years ago

I've been trying to convert the CityGML models listed by yourselves on the CityGML wiki but have had no luck to date. I assumed it was because they are using version 1.0 of CityGML, but even when changing the schema to 2.0 the converter crashes.

Here's an example crash (the others fail at the same point when changed to a 2.0 schema):

CityGML2OBJ. Searching for CityGML files...
1-10-STADSDRIEHOEK
    There are 848 cityObject(s) in this CityGML file.
    Analysing buildings and extracting the geometry...
Traceback (most recent call last):
  File "CityGML2OBJs.py", line 378, in <module>
    poly_to_obj(poly, 'All')
  File "CityGML2OBJs.py", line 149, in poly_to_obj
    t = polygon3dmodule.triangulation(epoints, irings)
  File "./CityGML2OBJs/polygon3dmodule.py", line 455, in triangulation
    tris = t['triangles']
KeyError: 'triangles'

I don't know much about CityGML but the geometry seems ok and the fact that this occurs for all the real cities I've tried makes me think that it's either some part of the 1.0 schema that I've missed, or there's an issue converting these files at the moment. For the record, the converter works fine for the random CityGML data generator you created.

Can you enlighten me on whether this is indeed an issue because of 1.0 (and what specifically might be causing it), or whether there is something else going wrong? I'd be happy to try and fix it but I don't know what I'm looking for right now (I'm new to CityGML).

fbiljecki commented 9 years ago

Thanks for this report and for trying the code. I intend to work on improving the converter to support CityGML 1.0, and also to improve the detection of the invalid geometries to avoid such crashes. The error that you have experienced has likely been caused by invalid geometry in the dataset, which is not surprising considering that public datasets are usually full of invalid geometries. The built-in geometry validator is a basic one, and in some public datasets I have encountered nastier errors that cause the embedded triangulator to crash (sometimes also with a C error that cannot be excepted in Python). However, that's not an excuse not to improve this converter to detect them better and skip them. I will come back to you in a few weeks.

robhawkes commented 9 years ago

Thanks for the update Filip! This is a great tool and it will be very useful for myself and the people who use ViziCities and other services that I work on that utilise CityGML models.

If it helps, the same CityGML models that fail converting using CityGML2OBJs actually import into 3DCityDB ok and can be exported out as collada models. Perhaps 3DCityDB fixes broken geometry as I noticed it had detected polygons without an endpoint and used the start point to create a new one. I suppose in this case, it's more useful to fix the geometry if we can than it is to just detect and ignore it (especially if the errors are common and known).

kannes commented 9 years ago

Same issue here with data from http://suche.transparenz.hamburg.de/dataset/3d-stadtmodell-hamburg using a re-written header.

Here is an example file (with the header for 2.0, hopefully correct): http://pastebin.com/FPMpgrga (https://www.govdata.de/dl-de/by-2-0)

fbiljecki commented 9 years ago

Noted, thanks for the report. It seems that the demand for solving this shortcoming is increasing, so I'll investigate and work on it as soon as I'll have time.

fbiljecki commented 9 years ago

Hello,

Sorry for the long break, busy times. I've worked on solving the errors which you have encountered. Probably you've already managed to convert the data with some other utility (I also know that Rob has been developing his tool). If you are interested, I've updated the code, and while it still has some hiccups and it returns errors in some files, many data sets that previously didn't work are now supported. The code now works with CityGML 1.0. I tried it with Rotterdam, Lyon, and Hamburg (see the picture below). Let me know of data sets that do not work, so I'll take a look.

2015-08-08 at 15 53