001] CityEngine Tutorial : Create 3D Buildings from SHP File (Extrude + CGA Guide)
In this tutorial, you will learn how to automatically generate building heights using SHP files. This is the most fundamental process of 3D modeling using GIS data.
📌 What You'll Learn
- How to import SHP files correctly into a CityEngine workspace
- Mapping GIS attributes (Floor Count) to 3D geometry parameters
- Writing basic CGA (Computer Generated Architecture) rules
- Automating mass modeling for large-scale urban environments
Generating a 3D city from 2D geospatial data is the cornerstone of Digital Twin and Smart City infrastructure projects. In this session, You will master the extrude function in CityEngine to automate the 3D modeling process using GIS attribute data, specifically the floor count.
In this tutorial, you will start with a very simple task to create 3D buildings.
|
|
|
[Final - 3D buildings generated based on the floor attribute] |
You will be using the attribute values of an SHP file to give height to
building structures.
If you have a building SHP file downloaded from the
National Geographic Information Platform, you can use that, or you can use the
example file provided below.
Attachment: 01 - extrude.zip (This files are verified for safety and are directly hosted on Google Drive.)
Once you unzip the downloaded zip file, you will see several files as shown below.
|
|
|
[img 1 : List of files including building.shp, dbf, prj, shx, and
cpg]
|
SHP File Composition
If you open the building.shp file among these in GIS software (Q-GIS, Arc GIS, etc.), the buildings will appear. (The visualization might look slightly different.)
|
|
|
[img 2 : SHP file loaded into GIS software showing building
footprints]
|
Buildings contain various attributes as shown below, but in this lecture, you will only use the NMLY value, which corresponds to the number of floors.
(Details for each attribute can be found on the National Geographic Information Map.)
|
|
|
[img 3 : Attribute table showing building data with the NMLY field
highlighted]
|
Step 1: Launch CityEngine
Now, launch CityEngine.
The trial version can be downloaded at https://www.esri.com/en-us/arcgis/products/arcgis-cityengine/trial after signing up for an ESRI account. (Note: Gmail or Naver email addresses might not work; try using a different email address if needed.)
Create a New Project
Create a new project by navigating to the File menu.
|
|
|
[img 4 : CityEngine File menu highlighting New...]
|
Select CityEngine Project and click the Next button.
|
|
| [img 5 : New Project wizard selecting CityEngine Project] |
Enter '2023_Cityengine' as the Project name and click the Finish button.
|
|
| [img 6 : Entering the project name in the Project folder wizard] |
Once the project is created, you can see the following folder structure in the Navigator panel.
|
|
| [img 7 : Project folder structure in the Navigator panel] |
Step 2: Create a Scene
After creating the project, you need to create a Scene where the SHP file will be loaded. (A project can contain multiple scenes.)
|
|
| [img 8 : File menu selecting New] |
Select CityEngine Scene and click the Next button.
|
|
| [img 9 : Selecting CityEngine Scene in the New wizard] |
Enter '01_extrude.cej' in the File name field and click the Finish button.
|
|
| [img 10 : Naming the new scene file 01_extrude.cej] |
Clicking 'Finish' will result in the following screen. This is the basic CityEngine interface, consisting of a toolbar at the top and various panels.
|
|
| [img 11 : Basic CityEngine workspace screen] |
Step 3: Import SHP File
Copy the unzipped building.shp and related files into the data folder of the '2023_Cityengine' project. (You can paste them anywhere, but as you use the software, you'll naturally understand why they should go in the data folder.)
|
|
| [img 12 : SHP related files placed in the Navigator's data folder] |
Now, you need to import the building.shp file.
|
|
| [img 13 : Right-clicking the SHP file in the Navigator and selecting Import...] |
To place the SHP file at the correct coordinates, you must select the prj file.
Click the folder icon at the top left to select the prj file containing the coordinate system information.
|
|
| [img 14 : Shapefile Import wizard showing coordinate system settings] |
|
|
| [img 15 : Select Scene Coordinate System dialog] |
Select the 'building.prj' file that came with the building.shp file.
|
|
| [img 16 : Browsing for building.prj file] |
Click OK.
|
|
| [img 17 : Coordinate system confirmed as Korea 2000 Central Belt] |
The polygons from the building.shp file will now be displayed on the screen.
|
|
| [img 18 : Building polygons loaded into the 3D View] |
If you click one of the polygons and open the Object Attribute tab in the Inspector panel on the right, you can see the attributes of that polygon.
The attribute you need to raise the building is NMLY. The selected polygon here is a 1-story building.
|
|
| [img 19 : Checking object attributes in the Inspector panel] |
Step 4: Create CGA Rule
Now that the attributes and polygons are ready, let's create a CGA file to connect the two.
Create a new Rule file.
|
|
| [img 20 : File menu selecting New -> CGA Rule File] |
'Container' is where the Rule file will be saved. Leaving it as default will save it in the rules folder of the current project. Enter '01_extrude.cga' as the File name.
|
|
| [img 21 : Naming the CGA rule file] |
Try to avoid spaces and use English for file names. As you get used to CGA, rule files often reference each other, and spaces can cause issues.
The 01_extrude.cga file has been created next to the Scene panel.
|
|
| [img 22 : CGA Rule editor panel] |
Please type the following code:
attr BD_Floor = 0
Lot --> extrude(y, BD_Floor*3)
Variables declared with attr can be adjusted in the Inspector window.
Briefly explaining the code : it creates a variable named BD_Floor and uses the extrude command to raise it along the y-axis by a value equal to BD_Floor multiplied by 3. (The unit is meters.)
Deep Dive into CGA Rule Syntax for Beginners
Understanding how CityEngine interprets these two lines of code is crucial for expanding your procedural modeling skills. The first line, attr BD_Floor = 0, is not just a static variable; it acts as a dynamic gateway between your external GIS shapefile and CityEngine’s internal 3D engine. By naming it with the attr prefix, you allow the software to automatically expose this parameter to the Inspector panel, giving you the power to override values globally or on a per-feature basis without altering the underlying code structure.
The second line utilizes the Lot --> start rule, which targets the initial 2D polygons imported from your SHP file. The extrude(y, BD_Floor * 3) command then pushes that flat geometry into the vertical 3D space along the y-axis. Multiplying the floor count by 3 is a standard architectural conversion factor in urban planning simulations, assuming an average floor-to-ceiling height of 3 meters for residential and commercial structures. If you are modeling industrial complexes or high-ceiling modern lobbies, you can easily tweak this multiplier directly within the CGA editor to reflect accurate real-world dimensions.
Once typing is complete, save the file.
Step 5: Assign Rule and Connect Attribute
Drag your mouse to select all polygons in the 3D View panel.
|
|
| [img 24 : Selecting all polygons in the 3D View] |
In the Rules tab of the Inspector panel, you will see 'Rule File'. Click Assign... and select the '01_extrude.cga' file you just wrote. (The polygons must remain selected.)
|
|
| [img 25 : Assigning the CGA rule file in the Inspector panel] |
|
|
| [img 26 : Browsing for 01_extrude.cga in the rules folder] |
Once selected, the contents of the Rules tab will change, and the BD_Floor item, which you declared in the CGA file, will appear.
|
|
| [img 27 : Inspector showing the BD_Floor attribute under the rule file] |
Now, let's connect BD_Floor to NMLY. Click the down arrow to the right of BD_Floor and select Connect Attribute.
|
|
| [img 28 : Selecting Connect Attribute from the dropdown menu] |
In the Attribute Connection Editor, click on the 'Select layer' dropdown under 'Layer attribute' and select Shapes building.
|
|
| [img 29 : Choosing the building layer as the source] |
Click 'Select source' below, choose NMLY from the attributes of that SHP file, and click the OK button.
|
|
| [img 30 : Connecting the BD_Floor attribute to the NMLY source field] |
Final Result
Now, if you click the Generate button on the top toolbar...
|
|
| [img 31 : Clicking the Generate button on the toolbar] |
The polygons will extrude by the NMLY value multiplied by 3, as shown below.
|
|
| [img 32 : Final 3D buildings generated based on the floor attribute] |
You have just completed the simplest way to raise buildings.
Next time, we will look into how to generate terrain and place buildings on top of it.
If you encounter any issues, feel free to leave a comment. I've dealt with various GIS data errors and would be happy to help you out!
- To learn the fundamentals of procedural modeling and 3D terrain alignment in CityEngine, see [002-003] How to Create Terrain and Align 3D Buildings in Esri CityEngine
Comments
Post a Comment
Feel free to leave a comment if you have any questions about Global Mapper or CityEngine. I will get back to you with a sincere response as soon as possible. (Please note that all comments are moderated and manually approved to maintain a high-quality community. Promotional or spam content will not be published.)