Exercise 03, 04: Working with CityGML¶
The goals of exercises are to familiarize yourselves with CityGML and how the UML models and data schema translate into 3D models. For visualization of CityGML models, FME (Feature Manipulation Engine) by Safe software is used. Please use the lab systems for this exercise as they already have FME installed.
In Exercise 03 on 02.06.2026: You will work on Task 1 as a team of two.
In Exercise 04 on 09.02.2026: You will import the final dataset from Task 1 into an instance of the 3DCityDB.
Once you are done with this exercise, you would have learnt these key points.
Working with CityGML files and understanding how the UML diagrams can be mapped to concrete 3D models.
Enriching CityGML models with textures, external 3D models and additional attribute information of the environment.
Using transformers within FME to edit, manipulate data to harmonize different datasets to suit the needs of you application and to export/share the CityGML models in various formats.
Exporting to the 3DCityDB schema using the importer/exporter tool via command line. Setting up for the last exercise on the 3DCityDB.
Exercise Tasks¶
For a successful exercise, you must perform the following tasks (1 and 2), get your final CityGML dataset (with all the components) and push it to the 3DCityDB. This is to reinforce how the concept of CityGML (that you learnt in the lectures) can be translated onto various platforms, thereby serving so many diverse applications.
Task 1: Working with CityGML in FME¶
This is a team work. You will be assigned a partner randomly and each team will work on the subtasks of Task 1.
Most of you are familiar with FME already. If you are not, please check the FME - Feature Manipulation Engine. You would have to use FME transformers to complete the tasks.
Info
In case of any doubts regarding the transformers, either refer to FME’s official website or ask the tutors. Hints (for possibly useful transformers) are provided for each sub-task throughout the documentation. Each Transformers has a specific configuration of parameters that you must test and adjust to your task. Please carefully check them!
Before you start please check the data provided to you and the data you need to find and download by yourself.
The datasets check-marked in the following list are provided in OneDrive and on Moodle and the unfilled items are required to be downloaded by you.
A base dataset of the Quadrant in CityGML LoD2 [adapted from the standardized open data downloaded from LDBV open data portal]: TUM_CityGMLv2_LoD2.gml
A street space model of the area around the TUM Campus in CityGML: TUM_Streets_CityGMLv2.gml
A tree cadastre model for the area around TUM in CityGML: TUM+Surrounds_SolitaryVegObjects.gml
CSV List of LoD3 buildings present in the TUM2Twin Dataset
LoD3 Building of the TUM Campus - TUM2TWIN dataset [This data can also be downloaded directly from the given website also. Please download the models which you need, otherwise it is a very large dataset]
#Please use git to get the datasets. If you have git installed in your systems, simply use the following in the command line Terminal. You can also get the repository via Git in Visual Studio Code.
git clone --depth 1 git@gitlab.lrz.de:tum-gis/tum2twin-datasets.git
High-Resolution Aerial Images from Bayern Open Data Portal [This data needs to be downloaded by each group].
Important
Before you start off on your sub-tasks - Open all your datasets (that have spatial characteristic) in “FME Data Inspector” and really inspect the dataset. Please check if all your data is in the same coordinate system and aligned on the same level. There could always be variations which will cause problems later. The expected coordinate Reference system of your final dataset is “EPSG: 25832” which refers to “ETRS 89 - UTM Zone 32N”. This is important, otherwise importing the dataset to the Database will fail.
Hint
When converting from Gauss-Kruger to UTM (if necessary), a z-offset of -46.5 is required to align the models. You can use the FME Transformer offsetter for this purpose.
Note
All ETL processes (like the FME workflow) have an input (Readers in FME), Transformers, and Output (Writers).
In this sub-task, you need to evaluate the LoD2 and LoD3 datasets. Replace the LoD2 buildings with LoD3 models where available. (Not all LoD2 buildings have LoD3 counterparts). Once all the building models (LoD2 and LoD3 where available) are combined, apply the styling mentioned in the last point in this task.
The logic of the workflow is given here along with hints. Consider the LoD2 Model dataset as ‘Set A’ and the LoD3 Models as ‘Set B’.
Use the CSV file (with the gmlid and gml_parent_id) to extract all the buildings from the LoD2 dataset which do not match the LoD3 models in the CityGML_LoD3_folder i.e., your are leaving out the LoD2 models for which there is a corresponding LoD3 model in the dataset.
Hint: Match the gml_id of the LoD2 models to the LoD3 models. You can try using the FeatureMerger Transformer.
Replace the left-out LoD2 models with the LoD3 models. Use the same logic as above. Match the gml_id of the LoD3 buildings (which were used in the previous step) from the csv with the full CityGML LoD3 model.
Hint: Use another FeatureMerger transformer to identify the building models with the gml_ids in your quadrant. Since you only need the buildings that have a corresponding model in your previous step, connect the “UsedSupplier” output from the first FeatureMerger to the FeatureMerger_2. This will give you all the buildings and the walls.
Since the LoD3 models also have the openings (windows and doors) and these do not have corresponding entities in the LoD2 dataset, they need to be extracted from the LoD3 dataset by using the walls (which are the parents of the openings).
Hint: Use another FeatureMerger - FeatureMerger_3 - to match the gml_parent_id of the windows and doors (requestor) to the ‘gml_id’ of the geometries merged in the previous step.
But now, you see that all the features are bundled into a single output unit. These need to be separated back into the layers that we had from the input (reader).
Hint: Use the FeatureTypeFilter to get back all the individual layers.
Set Appearance to the Building Models. Roofs need to be ‘Red’ (HEX-#aa0000), Walls need to be ‘Light Grey’ (HEX-#efebdb) and Openings (Windows and Doors) need to be ‘Black’ (HEX-#000000).
Export the combined dataset using the “OGC CityGML” writer.
Hint: When writing out the data, choose to create the writer “Feature Type Definition” = “Copy from Reader”
Task B1 - In this sub-task, you need to apply textures from the High-res Aerial Images to the street spaces. You only need to do this for the streets in your Quadrant, not the full dataset. The logic of the task is as follows.
Get the bounding box of your Quadrant from the LoD2 base dataset and clip the streets.
Hint: Try using the BoundingBoxAccumulator and Clipper transformers.
Import the 20cm GeoTiff Aerial Orthophotos downloaded from the Bayern Open Data Portal. The Tiles from the open data do not exactly align with the quadrant of the TUM base dataset - hence - mosaic them to have one complete uninterrupted aerial image.
Hint: You can use the Mosaicker transformer here.
Clip the Aerial photo to the streets (clipped to the quadrant extents).
Hint: Use the Clipper tool again.
Set Appearance to the streets using the clipped Aerial photos as the “Appearance” and the the clipped streets as the “Geometry”.
Hint: Use the AppearanceSetter transformer here.
Additionally, you can also group the appearance by ‘gml_id’. This will make sure that every street segment with a unique gml_id has its attached appearance.
Hint: Use the AttributeKeeper after Clipper and select “gml_id”. When setting appearance in the AppearanceSetter, choose to group by the gml_id.
Task B2 - In this sub-task, you need to clip the vegetation dataset to your Quadrant extent and then apply appearance to your trees
The tree appearance needs to be in ‘green’ (HEX-#55aa7f).
Hint: You can follow a similar procedure to the one explained in sub-tasks B1.
Export the combined dataset using the “OGC CityGML” writer.
Hint: When writing out the data, choose to create the writer “Feature Type Definition” = “Copy from Reader”
Important
Once you are done with the sub-tasks A and B - Please combine both the CityGML Files (Buildings and StreetSpace + Vegetation into a single file) i.e., in the end every group must have a single CityGML file that consists of the LoD2, LoD3 buildings, street spaces and Vegetation.
Task 2: Create a CityDB instance with Docker and Import the final dataset from task 1¶
Download and install Docker
How do you speak to docker??
Please use the Window Powershell / Command line Terminal to command Docker once it is installed.
How do you actually use the citydb-tool??
Download the citydb-tool-1.0.0.zip from the above github repository. Unzip it.
Open the commandline from the folder by typing in “cmd” in the folder location bar. This will open the command line with that directory. Copy and paste the above code in the commandline interface. DO NOT forget to adapt the path to your final CityGML in the last line of the code!
Please import the CityGML file into the 3DCityDB - CityGML mapped onto Spatial Relational Databases which we will look at in the upcoming lectures - using the following CLI command. A detailed documentation of about the 3DCityDB is available here.
#Create the 3DCityDB Instance
#CHANGE THE DETAILS IN THE COMMAND AFTER YOU COPY!!
docker run -d -p <Portnumber:5432> --name <name_of_the_container> -e POSTGRES_DB=citydbv5 -e POSTGRES_USER= <user_name> -e POSTGRES_PASSWORD= <user_password> -e SRID=25832 3dcitydb/3dcitydb-pg
Use the details (used in the docker instance) to create/login to the server on pgAdmin to check if your database is created with all the required tables. Please click and explore the database that is created.
Use the following command to import into the database you created. Follow the citydb documentation for more information.
#Import Data into the database you have created now
#Change the details in the command as per your system!!!
citydb import citygml -P <Portnumber> -d citydbv5 -u <user_name> -p <user_password> folder/filename.gml
Task 3: Test SQL Queries on the 3D CityDB¶
Connect to the database via the “SQL Creator” transformer in FME. Run the following SQL Queries and visualize the results.
#Count the number of buildings in the dataset SELECT COUNT(*) AS building_count FROM citydb.feature JOIN citydb.objectclass ON objectclass_id = objectclass.id WHERE citydb.objectlass.classname = 'Building';#List all wall objects in descending order of their surface area, with a limit of 10 SELECT sd.id, sd.objectclass_id, ST_Area(gd.geometry) AS surface_area FROM citydb.surface_data sd JOIN citydb.geometry_data gd ON sd.id = gd.feature_id WHERE sd.objectclass_id = 709 ORDER BY surface_area DESC LIMIT 10;Take screenshots of the results and submit them along with the rest of the required files.
Submission¶
Please submit the following as a .zip folder. Individual submission of the team work is required.
The FME Workflow(s) created
The final CityGML model including all Buildings, street spaces, vegetation along with their textures.
Actual command used for setting up the citydb instance and import the data.
Screenshot of the
running docker container,
the database you created from pgAdmin.
The results in FME after running the Sample SQL Queries from Task 3.