Skip to content

Add buildings to CityGML files

This tutorial is to create a simple SOLID building in LoD1 with SketchUp and export it georeferenced to CityGML.

Note

This may or may not work with other LOD2 levels. It has only been tested with LOD1.

Setting up the SketchUp Template / Document

  1. Start SketchUp
  2. Go to File -> GeoLocation -> Add
  3. Select region as required and "grab" it.

Getting the coordinate origin for later georeferencing

  1. Find out the world coordinates of your SketchUp origin using GoogleMaps
  2. For this find the origin of your SketchUp coordinate system in GoogleMaps by comparing the images
  3. Place a marker at google maps (right click at desired location -> "what's here") which gives you the coordinates of this location in WGS84 Norting-Easting
  4. Copy and paste them in a text file for ease of use
  5. Go to: https://epsg.io/transform#s_srs=4326&t_srs=31467
  6. Convert your coordinates from WGS84 (Gmaps) to the desired one. Here we use "EPSG:31467 DHDN GK Zone3"
  7. Copy and paste the transformed coordinates in a text file for later use.

Modelling your buildings in SketchUp (LoD1)

  1. Save your current document, just in case we need to restart in the next step.
  2. Get the GEORES plugin and install it in SketchUp.
  3. Watch SketchUp tutorials on how to make simple buildings
  4. Once the buildings are made, select one at a time and click on the green house symbol from the GEORES Plugin Toolbar which says: "Erstelle ein neues Gebaeude"
  5. A PopUp appears, select "LoD1" -> ok, a new PopUp appears, select "Solid" -> ok.
  6. Repeat this for all buildings
  7. You can check that attributes of a building (e.g. gmlid) by going to the menu Tools -> GEORES citygml object dialog. Select an element and you can see the gmlid.

Exporting the SketchUp buildings to GML

  1. Go to menu Tools -> GEORES CityGML Export 2.0
  2. Fill in the values for Rechtswert, Hochwert with the ones we obtained before (in EPSG 31467)
  3. Fill in the height if you know it, else leave it empty. If you need this value depends on your application
  4. Select a path/file to store the GML.
  5. The other options don't seem to have an effect. Textures have not been tested.
  6. You must click on START now. If you close the dialog before clicking start it will not do anything!
  7. You will get a message that the file has been written successfully.

Reparing the exported GML

  1. There is a whitespace in one of the urls in the Tag which should not be there.
  2. Open the XML/GML file with a text editor and look for this:
    <core:CityModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://www.opengis.net/citygml/2.0 ./CityGML_2.0/CityGML.xsd"
                    remove the whitespace here............................^
    
  3. Add the envelope behind the closing tag ">" of <core:CityModel..... > and before <core:cityObjectMember>. For example:
    <gml:boundedBy>
        <gml:Envelope srsName="EPSG:31467" srsDimension="3">
            <gml:lowerCorner>3513011.5993 5409874.8736 300</gml:lowerCorner>
            <gml:upperCorner>3513155.2613 5410004.6246 310.5</gml:upperCorner>
        </gml:Envelope>
    </gml:boundedBy>
    
  4. To obtain the coordinates of the envelope either add and subtract as many meters as you need or follow the same procedure as you did to get the coordinates of the SketchUp origin.

Checking the results in FZKViewer and GoogleEarth

  1. Open the CityGML in FZKViewer
  2. Here you can look at your model. If you see strange behaviours like walls appearing and disappearing this means the surface normal vectors are pointing inwards. This can be corrected in SketchUp.
    1. To correct the normals right click on the affected surface and click on "reverse faces". Although it says "faces" it seems to only affect the on that has been right-clicked on.
    2. You need to save your model and go back to exporting it...
  3. When your model seems to be correct, in FZKViewer export it to KML via File -> Export -> GoogleEarth
  4. Double click the file and GoogleEarth should go to that location

Adding new buildings to an existing CityGML model

Assuming that both CityGML files have the same coordinate reference system, it is possible to copy-paste buildings from one CityGML file to another.

To do so, open both CityGML files in a text editor with syntax highlighting (e.g. NotePad++), and copy the corresponding buildings, starting at <core:cityObjectMember> and ending at </core:cityObjectMember>.

  • CityGML 1:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <core:CityModel ...>
      <core:cityObjectMember>
        <bldg:Building gml:id="A">
            ...
            ...
            ...
        </bldg:Building>
      </core:cityObjectMember>
      <core:cityObjectMember>
        <bldg:Building gml:id="B">
            ...
            ...
            ...
        </bldg:Building>
      </core:cityObjectMember>
    </core:CityModel>
    
  • CityGML 2:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <core:CityModel ...>
      <core:cityObjectMember>
        <bldg:Building gml:id="C">
            ...
            ...
            ...
        </bldg:Building>
      </core:cityObjectMember>
    </core:CityModel>
    
  • CityGML 1 + 2:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <core:CityModel ...>
      <core:cityObjectMember>
        <bldg:Building gml:id="A">
            ...
            ...
            ...
        </bldg:Building>
      </core:cityObjectMember>
      <core:cityObjectMember>
        <bldg:Building gml:id="B">
            ...
            ...
            ...
        </bldg:Building>
      </core:cityObjectMember>
      <core:cityObjectMember>
        <bldg:Building gml:id="C">
            ...
            ...
            ...
        </bldg:Building>
      </core:cityObjectMember>
    </core:CityModel>
    
cityObjectMember or Building?

In the video tutorial shown below, Buildings are copy-pasted around <bldg:Building>, which seems to work. It is advised to copy-paste <core:cityObjectMember>, though.