Demo: View CityJSON

This demo illustrates how to load and view a CityJSON city model.

To run the demo, type:

$ python view_cityjson.py

Purpose

This demo demonstrates how to download a CityJSON file from an external URL, load the city model from the file, and visualize it using the DTCC platform.

Step-by-step

  1. Download CityJSON File: Retrieve a CityJSON file from a specified URL. This file contains the city model data in the CityJSON format.

    from urllib.request import urlretrieve
    url = "https://3d.bk.tudelft.nl/opendata/cityjson/3dcities/v2.0/DenHaag_01.city.json"
    urlretrieve(url=url, filename="city.json")
    
  2. Load City Model: Use the load_city function provided by DTCC to load the city model from the downloaded CityJSON file.

    import dtcc
    city = dtcc.load_city("city.json")
    
  3. View the City Model: Visualize the loaded city model by invoking its view() method.

    city.view()
    

Complete Code

Below is the complete code for this demo:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# This demo illustrates how to load and view a CityJSON city model.

import dtcc
from urllib.request import urlretrieve
import tempfile
import os

# Download example CityJSON file
url = "https://3d.bk.tudelft.nl/opendata/cityjson/3dcities/v2.0/DenHaag_01.city.json"
temp_path = tempfile.NamedTemporaryFile(suffix=".json", delete=False)
urlretrieve(url=url, filename=temp_path.name)

# Load city model from CityJSON file
city = dtcc.load_city(temp_path.name)

# View city
city.view()

# Clean up
temp_path.close()
os.unlink(temp_path.name)