[IfcOpenShell] Cityjson to IFC

edited March 2023 in General

Can someon explain of make a screencast how Cityjson files can be converted to IFC using all of these codes?
Would be helpful for many i think.

https://github.com/IfcOpenShell/IfcOpenShell/tree/v0.6.0/src/ifccityjson

«1

Comments

  • Maybe we should ship it with the BlenderBIM Add-on and build a small UI for it, to make it more accessible to more users? Ping @LaurensJN ?

  • @magicalcloud_75 I could make an extended install guide on the OSArch wiki.
    @Moult might be a good idea. Also because it is dependent on the ifcopenshell.api that currently is not shipped with the python distributions in http://ifcopenshell.org/python but are with BlenderBIM. However it also has a cjio dependency. You think that's a problem?

    magicalcloud_75Coen
  • @magicalcloud_75 I forgot to make the tutorial, sorry about that. Here you can find it: https://wiki.osarch.org/index.php?title=Ifccityjson.

    @Moult I'm still up for making a small CityJSON importer UI in BlenderBIM. How can I get it to ship with it so I could make the UI? Also, is the cjio dependency a problem in that case?

    magicalcloud_75AceCoen
  • Good job Laurens. We have a FME running for us that does these kinds of jobs quite well. Not much of a programmer but would love to be able to use a FOSS solution to make IFC cityjson available for my own activities.

    LaurensJN
  • I followed the steps in the tutorial, maybe I am doing something wrong, it still can't find the ifcopenshell.api module. I am on Windows 10 and using Python 3.9.
    What I did:

    1. Went to my system installed python and installed cjio using pip install cjio . It worked, I now have cjio.exe in my scripts folder

    2. Downloaded the latest BlenderBIM add-on, extracted it and placed the ifcopenshell module in my local Python installation

    3. Git cloned IfcOpenShell to my local machine
      C:\Code\IfcOpenShell\src\ifccityjson

    1. Went to the ifccityjsonfolder

    2. Tried to run the script through powershell

      Windows PowerShell
      Copyright (C) Microsoft Corporation. All rights reserved.
      
      Try the new cross-platform PowerShell https://aka.ms/pscore6
      
      PS C:\Code\IfcOpenShell\src\ifccityjson> python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" n -o C:/Users/user/Documents/3DBAG.ifc -n identificatie
      Traceback (most recent call last):
        File "C:\Code\IfcOpenShell\src\ifccityjson\ifccityjson.py", line 21, in <module>
          from cityjson2ifc import Cityjson2ifc
        File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 20, in <module>
          import ifcopenshell.api
      ModuleNotFoundError: No module named 'ifcopenshell.api'
      PS C:\Code\IfcOpenShell\src\ifccityjson>
      

    I feel I am missing something in step 2. I cant't find any file or folder called .api. Still missing the ifcopenshell.api. What am I doing wrong?

  • Great that you tried to follow it @Coen! And I think you are entirely correct that something is missing in step 2. If I download the BlenderBIM add-on and navigate to blenderbim/libs/site/packages/ifcopenshell, the api folder is there, while in your folder it is missing...

    Did you download the latest add-on from https://blenderbim.org/download.html? I'm not sure why your directory looks different otherwise..

  • @LaurensJN

    Your tutorial is correct, the problem was me. I already had an ifcopenshell folder there before I even installed BlenderBIM, somehow it didn't copy paste the api folder.

    Unto to next challenge,. :-). I typed in this command in Command Prompt:

    python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie

    Gives the following output:

    Traceback (most recent call last):
      File "C:\Code\IfcOpenShell\src\ifccityjson\ifccityjson.py", line 49, in <module>
        converter.convert(city_model)
      File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 91, in convert
        self.create_IFC_classes()
      File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 227, in create_IFC_classes
        IFC_geometry, shape_representation_type = self.geometry.create_IFC_geometry(self.IFC_model,
      File "C:\Code\IfcOpenShell\src\ifccityjson\geometry.py", line 51, in create_IFC_geometry
        IFC_geometry = self.create_IFC_surface(IFC_model, geometry)
      File "C:\Code\IfcOpenShell\src\ifccityjson\geometry.py", line 126, in create_IFC_surface
        IFC_faces.append(self.create_IFC_face(IFC_model, face))
      File "C:\Code\IfcOpenShell\src\ifccityjson\geometry.py", line 136, in create_IFC_face
        vertices.append(self.vertices[tuple(vertex)])
    KeyError: (205925.252, 445764.534, 0.0)
    

    I also tried to copy paste what was in the tutorial:
    "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" n -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie

    Gives the following output, I think a dash is needed before the first n? Might be a small mistake in the tutorial?

    ifccityjson.py: error: unrecognized arguments: n

    So I placed a dash but now got this:
    C:\Code\IfcOpenShell\src\ifccityjson>python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -n -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie

    ifccityjson.py: error: argument -n/--name: expected one argument

  • Let me start with the second question: the first 'n' should not be there at all. There only is one argument '-n' or '--name' (the attribute that has the name, in case of 3DBAG 'identificatie' . So if you would type C:\Code\IfcOpenShell\src\ifccityjson>python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie it should work.

    The first question is a bit more difficult. That is probably a bug in in the converter. I think it has to do with the identifier being a float tuple instead of an int tuple. I will try to fix that.

    Thanks for testing it out! It is always better if somebody else finds some bugs that you couldn't find yourself :)

  • Thanks for the answer, I am getting this error now

    I typed in the command prompt:
    C:\Code\IfcOpenShell\src\ifccityjson>python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie

    It returns this

    Traceback (most recent call last):
      File "C:\Code\IfcOpenShell\src\ifccityjson\ifccityjson.py", line 49, in <module>
        converter.convert(city_model)
      File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 91, in convert
        self.create_IFC_classes()
      File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 227, in create_IFC_classes
        IFC_geometry, shape_representation_type = self.geometry.create_IFC_geometry(self.IFC_model,
      File "C:\Code\IfcOpenShell\src\ifccityjson\geometry.py", line 51, in create_IFC_geometry
        IFC_geometry = self.create_IFC_surface(IFC_model, geometry)
      File "C:\Code\IfcOpenShell\src\ifccityjson\geometry.py", line 126, in create_IFC_surface
        IFC_faces.append(self.create_IFC_face(IFC_model, face))
      File "C:\Code\IfcOpenShell\src\ifccityjson\geometry.py", line 136, in create_IFC_face
        vertices.append(self.vertices[tuple(vertex)])
    KeyError: (205925.252, 445764.534, 0.0)
    
  • I found the bug: CJIO had an update that broke some code. I posted an issue there and will update if I got an answer

    Coen
  • It should be fixed now (see commit). You can download ifcopenshell again, or (might be easier), go to src/ifccityjson/ifccityjson.py and change line 39: city_model = cityjson.load(args.input) to city_model = cityjson.load(args.input, transform=False)

  • Sorry for the late reply @LaurensJN . Indeed it would be awesome to ship it with the BlenderBIM Add-on. The cjio dependency can be added to https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/blenderbim/Makefile - you can see other examples of other Python libs already bundled there.

    You can also see some example code for other importers such as for P6 / MSProject in the sequence module. I think it might be appropriate to create a new module for cityjson. Perhaps a module named gis? Just in case you foresee future development around GIS features. Once you've created a new module here is some existing code you can use as an example: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/blenderbim/blenderbim/bim/module/sequence/init.py#L127-L128 and L141 and L151. And the corresponding operator code: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/blenderbim/blenderbim/bim/module/sequence/operator.py#L1079-L1098

  • @LaurensJN said:
    It should be fixed now (see commit). You can download ifcopenshell again, or (might be easier), go to src/ifccityjson/ifccityjson.py and change line 39: city_model = cityjson.load(args.input) to city_model = cityjson.load(args.input, transform=False)

    Thanks, I changed line 39 like you said, ran the command again.
    python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie

    Now the console returns this:

        Traceback (most recent call last):
          File "C:\Code\IfcOpenShell\src\ifccityjson\ifccityjson.py", line 49, in <module>
            converter.convert(city_model)
           File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 91, in convert
             self.create_IFC_classes()
           File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 225, in create_IFC_classes
            IFC_semantic_surface_children = self.create_IFC_semantic_surface_children(geometry, lod)
          File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 290, in create_IFC_semantic_surface_children
            IFC_shape_representation =self.create_IFC_shape_representation(surface_geometry, 'brep', lod)
          File "C:\Code\IfcOpenShell\src\ifccityjson\cityjson2ifc.py", line 302, in create_IFC_shape_representation
            self.IFC_representation_sub_contexts[str(lod)], 'Body',
        KeyError: '1.2'
    
  • @Moult Thanks for the pointers, I'll be able to start there.
    @Coen I can't reproduce your error. Care to give me your file? You can send it to l.oostwegel (at) gmail.com

  • @LaurensJN said:

    @Coen I can't reproduce your error. Care to give me your file? You can send it to l.oostwegel (at) gmail.com

    .json file format is not allowed. I changed the file extension to .txt to attach to this post.
    I downloaded this file from the 3DBAG Viewer.

  • Thanks. My best guess is that this has again to do with the updated CJIO library, this time this issue. The metadata in the file is not properly updated, therefore it does not recognise the multiple LoDs in the file. We'll have to wait for their response to get it working again I'm afraid. Will keep you updated!

    Coenmagicalcloud_75
  • Make a 'City IFC for Dummies' video afterwards :)

  • @Coen issue is now solved inside ifccityjson until there is an update of CJIO where that bug is fixed. I came across another bug, which has to do with generation of interior holes in faces using IFC that I could unfortunately not solve (yet). I will make a post about that on the forum and hopefully somebody can help me :) Anyway, you can download the new code on github and your 3D BAG should have no errors anymore! The command changed ever-so-slightly, it is now best to use: python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie --lod 1.3 (or whichever lod you'd like to extract.).

    @magicalcloud_75 I will put some effort in merging ifccityjson inside BlenderBIM, which will make everything a lot more intuitive for a non-programmer, after that I promise to make a video!

    Coenbasweinmagicalcloud_75
  • edited November 2021

    @LaurensJN said:
    Anyway, you can download the new code on github and your 3D BAG should have no errors anymore! The command changed ever-so-slightly, it is now best to use: python ifccityjson.py -i "C:\Code\IfcOpenShell\src\ifccityjson\3dbag_v210908_fd2cee53_5624.json" -o C:\Code\IfcOpenShell\src\ifccityjson\3DBAG.ifc -n identificatie --lod 1.3 (or whichever lod you'd like to extract.).

    Absolutely fantastic!

    In BimCollabZoom

    And in BIMVision

    LaurensJN
  • Can .osm files also be converted to .ifc with this tool?

  • @magicalcloud_75 as promised, here's how to convert your CityJSON file to IFC using the latest (non-stable) BlenderBIM. You can download for example today's version at https://github.com/IfcOpenShell/IfcOpenShell/releases/tag/blenderbim-211117

    @Coen I'm afraid this will be something for the future :) Would be handy though...

    Coenmagicalcloud_75Gorgiousbaswein
  • After importing you could get an error, but this does not fail loading the IFC file. I should fix that soon though...

    magicalcloud_75
  • That is really amazing, would be cool to see this for the whole of Europe instead of the Netherlands. :-)

    Slightly related, can you also merge the different IFC tiles in Blender?

  • I guess you could achieve that in two ways: (1) do process above twice with a different .json file (IFC file gets saved where you specified in 'IFC Output') and use IfcPatch to merge IFCs (see https://community.osarch.org/discussion/447/import-and-merge-ifc).
    (2) merge the cityjson files using CJIO python library (using: pip install cjio). It's a CLI and you can find here https://github.com/cityjson/cjio how the merge function works. After merging multiple tiles, you can just import the big cityjson file as IFC in Blender. Hope that helps?

    Coen
  • edited November 2021

    This makes dutch NL 3DBAG data so much more usable! I think kadaster more or less forget to serve BIM. One thing catches my attention. It seems that the geo location is not stored in IFC. That can't be the case.. can it?? I am certainly not a ifc file spec specialist but this kind of crucial information should be stored IN ifc.

    Tile 4278

  • edited November 2021

    @LaurensJN [EDIT]
    RD notations in NL always contain 2x6 digits [m] in X & Y
    Epsg7415 IFC georeferencing, Shouldn't that be epsg:28992 ?

  • epsg:28992 is for Amersfoort / RD New.
    epsg:7415 is a compound coordinate system with Amersfoort / RD New + NAP height.
    See https://epsg.io/7415

  • @magicalcloud_75 said:
    This makes dutch NL 3DBAG data so much more usable! I think kadaster more or less forget to serve BIM. One thing catches my attention. It seems that the geo location is not stored in IFC. That can't be the case.. can it?? I am certainly not a ifc file spec specialist but this kind of crucial information should be stored IN ifc.

    Tile 4278

    I'm not exactly sure what you mean. It has the northings/eastings/OrthogonalHeight of the project center and an EPSG, do you need more?

  • This is so convenient, just a matter of clicking two or three buttons. What does the Identifier do by the way?

    LaurensJNmagicalcloud_75
  • @Coen said:
    This is so convenient, just a matter of clicking two or three buttons. What does the Identifier do by the way?

    If you want the building to have a specified attribute as building/entity name instead of its CityJSON identifier, you could use that instead. If you take a look at the CityJSON_attributes pset under 'Object properties' --> 'IFC Object Property Sets', you could choose any of these properties. In the previous version of 3D BAG, the object ID was not the same as the BAG ID, so you would put 'identificatie' in the 'Identifier' to get the actual BAG ID. I didn't really test it thoroughly though, because the new 3D BAG identifier is the BAG ID anyway. Another use case would be for example if the building address is specified in the CityJSON file, you could use that instead of the BAG ID. This is right now not the case for the 3D BAG dataset but might be useful for similar datasets in other countries?

    Coen
Sign In or Register to comment.