Pipeline importing 3D BAG data into Cesium ion

Hi there! This is not a question but simply a workaround / tutorial I have made to get all the 3D BAG tiles that you need without having to do everything manually using Python and Java.

Firstly, you will need Python. You can get Python from anywhere you like and you can run it anywhere as you please.

Secondly you will need Javascript.

After that we will make a small script. This script will scrape all the Json files from 3D BAG.

import requests

url_template = "https://data.3dbag.nl/cityjson/v210908_fd2cee53/3dbag_v210908_fd2cee53_{}.json"

for i in range(8115):
    response = requests.get(url_template.format(i))
    if response.status_code == 200:
        with open("3dbag_v210908_fd2cee53_{}.json".format(i), "wb") as f:
        print("Failed to download tile {}".format(i))

This Python script uses the requests library to download 8115 JSON files from a URL template. The URL template contains a placeholder “{}” which will be replaced by the current iteration number (0 to 8114) in the loop.

The loop iterates 8115 times and in each iteration, a request is made to the URL obtained by formatting the URL template with the current iteration number. The requests.get function returns a response object that contains the status code of the request and the content of the response (the JSON file).

If the status code of the request is 200 (success), the content of the response is written to a file named “3dbag_v210908_fd2cee53_{}.json”, where “{}” is again replaced by the current iteration number. The file is written in binary mode (using “wb”) to ensure the correct encoding.

If the request fails (status code is not 200), a message is printed indicating that it was not possible to download the tile.

This url_template will make a download request with a number ranging from 0 to 8115. This url will be updated when 3D BAG updates their download links.

In this case you will download ALL 3D BAG TILES! This is a big chunk to download with approximately 70GB on tiles.

Now that these are downloaded we can run another tool. This tool converts CityJson to CityGML.

However- do note that you will have to download THE FIRST VERSION on the Github! The first version uses CityGML 2.0 which is still supported by Cesium ion. The newest version is not!

With this tool you can easily convert ALL CityJson files by using the command

citygml-tools from-cityjson "JSON folder".

NOTE; Converting ALL CITY JSON FILES will result in a a batch of approximately 600GB in CityGML files!

Let this tool do it’s job. It might take a while so be patient! After this you can zip as many tiles as you like and upload those to Cesium ion! CityGML files will clamp to your terrain when you upload it. (you have to toggle this at the upload settings)

You can not upload ALL 3D BAG files at the same time due to the file sizes. So you’ll have to work around that by making chunks.

Hope this helps out anyone struggling with same issues I had.


1 Like