Whether you create a street graph from a shapefile or OpenStreetMap data, generate a graph using Graph > Grow Streets or draw streets manually with the Freehand or Polygonal Street Creation tools, CityEngine will draw your graph with geometry representing streets, sidewalks, intersections, and joints where street alignments bend. Your intersection choices include Roundabouts, the larger of which have center islands, the smaller of which are cul-de-sacs. Click on some individual pieces of geometry, a street or a sidewalk; look at the Inspector window and you will see Object Attributes. Where do these come from?
- For hand-drawn street geometry, CityEngine automatically generates attributes for connectionEnd, connectionStart, shapeType and type. For sidewalk types, CityEngine adds an attribute for sidewalkSide (Right or Left).
- Graphs from sources like OpenStreetMap will contain even more Object Attribute data like speed limit, road class (e.g. residential, parkway), direction and even cost.
So being able to access these attributes and perform operations in CGA code would be pretty useful.
Here’s how I did it for the diagram at the top of the page where shape types, including Right and Left sidewalk sides are individually colored.
/** * File: StreetParts.cga * Created: 1 Jul 2018 02:09:59 GMT * Author: Jeff Herzer | jeffherzer.com */ version "2017.1" # Street Shape Color Scheme @Hidden attr colorStreet = "#0000ff" # Blue @Hidden attr colorSidewalk = "#999999" # Gray @Hidden attr colorSidewalk_L = "#ff0000" # Red @Hidden attr colorSidewalk_R = "#00ff00" # Green @Hidden attr colorRoundabout = "#ff8040" # Orange @Hidden attr colorRoundaboutIsland = "#ffff00" # Yellow @Hidden attr colorJoint = "#00ffff" # Cyan # Initialize attributes @Hidden attr sidewalkSide = "" # Rules for each shape type Street --> color(colorStreet) Sidewalk --> case sidewalkSide == "Right": color(colorSidewalk_R) case sidewalkSide == "Left" : color(colorSidewalk_L) else : color(colorSidewalk) Roundabout --> color(colorRoundabout) RoundaboutIsland --> color(colorRoundaboutIsland) Joint --> color(colorJoint)
Create a CGA file using the example code, draw some streets and intersections and change some of your nodes from “Smart” to “Roundabout”. Right- and Left-side sidewalks are determined by the geometry’s origin and the direction in which you draw, as shown by the black arrows in the page top diagram.
To access the sidewalkSide attribute, you must first initialize it in your code with attr sidewalkSide = “”. Now we can conduct an operation based on the value. Under the Sidewalk rule we’ve applied conditional logic that assigns colors based on sidewalkSide. If you remove the initialized attribute and renegerate, the rule will not work.
Select all of your geometry and apply the StreetParts.cga rule file. It is not necessary to specify the StartRule because we have used rule names that match the shape type (Street, Sidewalk, Joint, Roundabout, RoundaboutIsland).