Demo: Build City Mesh

This demo illustrates how to build a city mesh from a point cloud and building footprints.

To run the demo, type:

$ python build_city_mesh.py

Purpose

This demo demonstrates how to download point cloud and building footprint data, process the data to extract roof points and compute building heights, and create a city model. From the city model, a city mesh is generated at a specified level of detail (LOD) and visualized.

Step-by-step

  1. Define Bounds: Specify the spatial bounds for a residential area in Helsingborg by setting a height/width value (here, 2000.0 units).

    h = 2000.0
    bounds = dtcc.Bounds(319891, 6399790, 319891 + h, 6399790 + h)
    
  2. Download Data: Retrieve the point cloud and building footprints for the defined bounds.

    pointcloud = dtcc.download_pointcloud(bounds=bounds)
    buildings = dtcc.download_footprints(bounds=bounds)
    
  3. Process the Point Cloud: Remove global outliers from the point cloud to improve data quality.

    pointcloud = pointcloud.remove_global_outliers(3.0)
    
  4. Build Terrain Raster: Construct a terrain raster from the processed point cloud. Parameters such as cell size, radius, and ground filtering are specified.

    raster = dtcc.build_terrain_raster(pointcloud, cell_size=2, radius=3,
                                       ground_only=True)
    
  5. Process Building Footprints: Extract roof points from the building footprints and compute building heights using the terrain raster.

    buildings = dtcc.extract_roof_points(buildings, pointcloud)
    buildings = dtcc.compute_building_heights(buildings, raster, overwrite=True)
    
  6. Create City Model: Instantiate a city object and add the processed building and terrain data. Buildings outside the terrain are removed.

    city = dtcc.City()
    city.add_terrain(raster)
    city.add_buildings(buildings, remove_outside_terrain=True)
    
  7. Build City Mesh: Generate a city mesh from the city model using a specified level of detail (LOD).

    mesh = dtcc.build_city_mesh(city, lod=dtcc.GeometryType.LOD0)
    
  8. Visualize the Mesh: View the resulting city mesh using the view() method.

    mesh.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
22
23
24
25
26
27
28
29
30
31
32
# This demo illustrates how to build a city mesh from a point cloud and footprints.

import dtcc

# Define bounds (a residential area in Helsingborg)
h = 2000.0
bounds = dtcc.Bounds(319891, 6399790, 319891 + h, 6399790 + h)

# Download pointcloud and building footprints
pointcloud = dtcc.download_pointcloud(bounds=bounds)
buildings = dtcc.download_footprints(bounds=bounds)

# Remove global outliers
pointcloud = pointcloud.remove_global_outliers(3.0)

# Build terrain raster
raster = dtcc.build_terrain_raster(pointcloud, cell_size=2, radius=3, ground_only=True)

# Extract roof points and compute building heights
buildings = dtcc.extract_roof_points(buildings, pointcloud)
buildings = dtcc.compute_building_heights(buildings, raster, overwrite=True)

# Create city and add geometries
city = dtcc.City()
city.add_terrain(raster)
city.add_buildings(buildings, remove_outside_terrain=True)

# Build city mesh
mesh = dtcc.build_city_mesh(city, lod=dtcc.GeometryType.LOD0)

# View mesh
mesh.view()