Select to view content in your preferred language

cityengine building height color

621
2
07-30-2019 01:39 AM
chojeo
by
Emerging Contributor

hi  ,

nice to meet you ~

i need some help ~

nmly is shp builing height attribute

i made this  grammer

with height attr , i would like to assign   color

but this code is error

what problem ?

attr NMLY = 0 

zoneColor =             
    case NMLY == "1" : 
        "#ff0000" 
    case NMLY == "2" : 
        "#00ff00" 
    else: 
        "#0000ff" 
  
  

@StartRule
Lot -->
  extrude(NMLY)
    color (zoneColor) 

0 Kudos
2 Replies
Luiz_AmadeuCoutinho
Frequent Contributor

Here a sample for you, using colors by attribute. 

CGA from: Tutorial_16_Urban_Planning__2016_1\rules\Context.cga

__________________

version "2014.1"


attr floors = 0
attr floorDelta = rint(rand(-1,1))
const floorheight = 3

@Range("Assembly","Agricultural","Educational","Industry","Mercantile","Office","Public","Residential","Service","Storage","Transport","Utility","Other","Unknown")
attr usage = "Residential"

buildingUsageColor (buildingUsage) =
case buildingUsage == "Assembly" : "#f8c283"
case buildingUsage == "Agricultural" : "#cccc00"
case buildingUsage == "Educational" : "#ad89ba"
case buildingUsage == "Industry" : "#7a85c8"
case buildingUsage == "Mercantile" : "#777777"
case buildingUsage == "Office" : "#B884D5"
case buildingUsage == "Public" : "#BCD4D5"
case buildingUsage == "Residential" : "#bb4646"
case buildingUsage == "Service" : "#d08c6e"
case buildingUsage == "Storage" : "#444444"
case buildingUsage == "Transport" : "#444444"
case buildingUsage == "Utility" : "#444444"
case buildingUsage == "Other" : "#444444"
case buildingUsage == "Unknown" : "#444444"
else /*error*/ : "#ffffff"

@Startrule
Context -->
extrude((floors + floorDelta)*floorheight)
color(buildingUsageColor(usage))

0 Kudos
CherylLau
Esri Regular Contributor

In the case statement, NMLY is being compared to a string "1", but NMLY is a float.  Take away the quotation marks around "1" and "2", and do the logical comparison to floats 1 and 2 like this:

attr NMLY = 0 

zoneColor =              
    case NMLY == 1 :  
        "#ff0000"  
    case NMLY == 2 :  
        "#00ff00"  
    else:  
        "#0000ff"  
0 Kudos