Colorizing Polygons based on an object attribute

2177
4
Jump to solution
10-30-2012 02:01 PM
ScottFujikawa
New Contributor III
Hi,
I've imported some shapes from ArcMap into CE and I am trying to create the same symbology that I had created, based values taken from their "Solar_Potential" attribute. I would very much appreciate some assistance with writing a rule that assigns a color to the imported shapes that have a certain value, (such as #FF0000 for Solar_Potential value of 3, #FFCC00 for Solar_Potential value of 2, etc).
Thank you,
Scott
1 Solution

Accepted Solutions
JoanneO_Brien
Occasional Contributor
Hi

I had a similar thing in mine, where I wanted different zones particular colours based on the zone attribute from the imported ArcGIS shapefile. What you need to do is write in the attribute to tell the rule file to search the shapefile for your "Solar_Potential" attribute and then use the conidtional rule. eg:

attr Solar_Potential = 0                   //this will tell it to search the shapefile for the attribute called Solar_Potential, or if the values are non numerical use ""  //Then add in the conidtional rule  SolarPotentialColor =               case Solar_Potential == 3 : ("#FF0000")              case Solar_Potential == 2 : ("#FFCC00")              else : ("#FFFFFF")  


Then when you're writing your code all you have to do is eg.

building--> color(SolarPotentialColor)


and it'll add in the corresponding colour! :)

View solution in original post

0 Kudos
4 Replies
JoanneO_Brien
Occasional Contributor
Hi

I had a similar thing in mine, where I wanted different zones particular colours based on the zone attribute from the imported ArcGIS shapefile. What you need to do is write in the attribute to tell the rule file to search the shapefile for your "Solar_Potential" attribute and then use the conidtional rule. eg:

attr Solar_Potential = 0                   //this will tell it to search the shapefile for the attribute called Solar_Potential, or if the values are non numerical use ""  //Then add in the conidtional rule  SolarPotentialColor =               case Solar_Potential == 3 : ("#FF0000")              case Solar_Potential == 2 : ("#FFCC00")              else : ("#FFFFFF")  


Then when you're writing your code all you have to do is eg.

building--> color(SolarPotentialColor)


and it'll add in the corresponding colour! :)
0 Kudos
ScottFujikawa
New Contributor III
Hi Ms O'Brien,
Thank you for your help in writing the cga file for colorizing the roof polygons. I need to find a source for all the cga grammar. The only change I made to your suggestion was to use "Lot -->"  because it wouldn't compile for me when I used "Building -->"
The results look great, just like what I had in ArcMap. 
Thanks again,
Scott
0 Kudos
JoanneO_Brien
Occasional Contributor
The best sources for learning cga is to go through the tutorials (especially the basic and advanced cga coding ones). There are video's associated with them online here: http://video.arcgis.com/series/62/cityengine

Also read through the help files on cityengine, they're really useful once you get into it!

As for the 'Building' not working, it depends what you're assigned as your StartRule in the Inspector window. The default is 'Lot' hence this worked for you, but this can be changed if you want to use a different start rule, for example if you have multiple startrules in one rule file. (if you're doing this use @StartRule above each rule to indicate which one's are new rules.This is useful when you want to use all the same attributes etc but split the building up differently etc.
0 Kudos
JoanneO_Brien
Occasional Contributor
What you want to do it link your code to the string, which is your hex values so:

attr lineColor = "" # these double quotation marks are what you use for linking to a sting in the attribute tables.


#also note that the attr name must be the exact same as the name in your object attr table

That should be all you need, the rest of your code looks good. hope it works now! :)
0 Kudos