[002-003] How to Create Terrain and Align 3D Buildings in Esri CityEngine

Set up a 3D terrain from grayscale heightmaps and align GIS building footprints using CGA rules in CityEngine.

In this tutorial, you will learn the fundamental process of setting up a CityEngine environment, generating 3D terrain from heightmaps, and aligning GIS building footprints. This is the most essential workflow for building realistic Digital Twins.

    📌What You'll Learn

    • How to set up a CityEngine workspace and organize GIS assets
    • Importing and configuring Heightmaps (TIF) and Textures correctly
    • Aligning 2D SHP footprints to 3D terrain elevation
    • Basic CGA (Computer Generated Architecture) extrusion logic

    Esri CityEngine is a powerhouse for urban planning and Digital Twin creation. Whether you are visualizing a smart city or conducting a massive scale environmental analysis, mastering CGA rules and terrain alignment is essential. In this guide, we will explore the core philosophy of CityEngine and walk through the practical process of generating 3D environments from GIS data and heightmaps.

    Understanding the Esri CityEngine Terrain Workflow

    This is the second installment of our series. If you are just starting, you may want to check [001] Create 3D Buildings from SHP File (Extrude + CGA Guide) to understand how data properties drive 3D geometry.

    This tutorial is not a generic "step-by-step" for absolute beginners. Instead, it is designed for those who have installed CityEngine, felt the initial excitement from the official gallery images, and perhaps felt overwhelmed by the CGA programming requirement. To truly master CityEngine, you need a mix of interest in both 3D modeling and programming.

    What is CGA in Esri CityEngine?

    CGA stands for Computer Generated Architecture. It is a specialized programming language designed to define the shapes and forms of buildings. Unlike traditional 3D software (like 3ds Max or Blender) where you manually move vertices, CityEngine is "hard-coding" software. You write rules, and the software generates the city.

    For official documentation, refer to the CityEngine Help and the CGA Reference. Since these resources are in English, using a translation tool like DeepL can be incredibly helpful for non-native speakers.

    CityEngine urban landscape generated via CGA coding
    figure 1 : CityEngine urban landscape generated via CGA coding

    Practical Note: The Learning Curve

    To fully utilize CityEngine, you should eventually familiarize yourself with GIS, 3D principles, CGA and Python. Python integration allows for advanced automation, though mastering CGA alone will take you very far in urban procedural modeling.

    How to Import Heightmaps into Esri CityEngine

    Why Heightmaps Are Important

    CityEngine does not generate terrain directly from raw numerical maps. Instead, it uses a heightmap (a grayscale image) created in a GIS program to define elevation. For accurate placement, your image must have a coordinate system file (.prj).

    Preparing Terrain Files and GIS Data

    Download the exercise file MapLayer.zip (Verified and safe file for CityEngine.)

    cityengine exercise file
    figure 2 : MapLayer.zip download

    I recommend using geoTiff (.tif) files over standard PNG or JPG for heightmaps to preserve precision. For this tutorial, we use a set of files including building footprints (SHP), a satellite image (JPG), and a terrain heightmap (TIF).

    Example of a grayscale heightmap used for terrain generation
    figure 3 : Example of a grayscale heightmap used for terrain generation

    After creating a new project and scene in CityEngine, copy your data into the respective project folders (data, images, maps).

    Project folder structure in the CityEngine Navigator panel
    figure 4 : Project folder structure in the CityEngine Navigator panel

    Creating a Terrain Map Layer

    There are two ways to add a Map Layer: right-clicking the file in the Navigator and selecting "Import," or using the top menu: Layer > New Map Layer....

    Selecting New Map Layer from the top menu
    figure 5 : Selecting New Map Layer from the top menu

    Choose Terrain from the wizard and click Next. Browse for your heightmap file.

    Selecting the Terrain option in the Map Layer Wizard
    figure 6 : Selecting the Terrain option in the Map Layer Wizard
    Browsing for the heightmap TIF file
    figure 7 : Browsing for the heightmap TIF file

    Setting Coordinate Systems Correctly

    Always ensure your Scene Coordinate System matches your data. When prompted, select the appropriate PRJ file (e.g., Korea 2000 Central Belt). If the coordinates are mismatched, your buildings will not sit correctly on the terrain.

    Selecting the coordinate system from the PRJ file
    figure 8 : Selecting the coordinate system from the PRJ file

    Applying Satellite Texture to Terrain

    Next, add a Texture File by browsing for your satellite imagery to drape it over the 3D terrain.

    Finalizing heightmap and texture settings
    figure 9 : Finalizing heightmap and texture settings
    3D view showing the textured terrain
    figure 10 : 3D view showing the textured terrain

    How to Align SHP Building Footprints to Terrain

    Importing Building Shapefiles

    Now, import your building footprints (building2.shp). Since the SHP file only contains 2D coordinates, the shapes will initially appear at the base level (zero elevation).

    Importing the building shapefile via the Navigator
    figure 11 : Importing the building shapefile via the Navigator
    Shapefile import settings and coordinate validation
    figure 12 : Shapefile import settings and coordinate validation
    Building footprints appearing flat on the ground plane
    figure 13 : Building footprints appearing flat on the ground plane

    Using Align Shapes to Terrain in CityEngine

    To move the footprints to their correct elevation, go to Shape > Align Shapes to Terrain.... In the Align Function, select Translate to Average and choose your terrain layer as the source.

    Accessing the Align Shapes to Terrain tool
    figure 14 : Accessing the Align Shapes to Terrain tool
    Setting the Align Function to Translate to Average
    figure 15 : Setting the Align Function to Translate to Average
    Building footprints now aligned with the terrain elevation
    figure 16 : Building footprints now aligned with the terrain elevation

    How to Create 3D Buildings with CGA Rules

    Finally, we turn these flat polygons into 3D structures using a rule file. In the Inspector panel, click Assign... under the Rule File section and select a CGA file.

    Writing a Basic Extrude Rule

    Please type the following code and save it as "**01_extrude.cga**":

    attr BD_Floor = 0
    Lot --> extrude(y, BD_Floor * 3)

    Understanding attr Parameters

    Variables declared with attr can be adjusted dynamically in the Inspector window.

    Assigning a CGA rule file in the Inspector
    figure 17 : Assigning a CGA rule file in the Inspector

    To link the building height to the data in your SHP file, click Connect Attribute next to your height parameter (e.g., BD_Floor). Select the SHP layer and the specific attribute (e.g., NMLY) that represents the number of floors.

    Connecting CGA attributes to shapefile data
    figure 18 : Connecting CGA attributes to shapefile data
    Mapping parameters
    figure 19 : Mapping the BD_Floor parameter to the NMLY attribute

    Generating Procedural Buildings from GIS Data

    Click Generate (or press Ctrl+G), and CityEngine will procedurally extrude the buildings based on the data and the terrain height.

    Final 3D urban model generated on the terrain
    figure 20 : Final 3D urban model generated on the terrain

    Translate to Average vs Translate to Minimum

    When working with very steep slopes, the "Translate to Minimum" function is usually best to keep building foundations somewhat level. If you use "Project All," the footprint might distort to follow the terrain perfectly, which isn't realistic for architecture.

    Summary and Next Steps

    We have successfully created a 3D environment by combining GIS shapefiles, heightmaps, and procedural rules. This foundation allows you to perform advanced urban analysis. In our next lecture, we will dive deeper into color-coding these buildings based on their usage.

    FAQ 

    What is the best heightmap format for Esri CityEngine?

    GeoTIFF (.tif) is generally the best option for CityEngine terrain workflows because it preserves elevation precision and supports coordinate system information through PRJ files.

    Why is the PRJ file important in CityEngine?

    The PRJ file defines the coordinate reference system used by GIS data. Without matching coordinate systems, terrain layers and building footprints may appear in incorrect locations or elevations.

    Continue Learning
    Explore complete tutorial collections for CityEngine and Global Mapper.

    Comments

    Popular posts from this blog

    029] How to Split Polygon Areas with Intersecting Lines in Global Mapper

    [008] How to Understand CGA Rule Structure in CityEngine (Beginner Guide)

    046] How to Create Parallel Offset Lines in Global Mapper