dividing a building into apartments. Add a boolean type attribute to each apartment.

992
2
06-20-2017 12:41 PM
SudarshanPokharkar
New Contributor

Lot -->
extrude(height)
split(x) {floor_height: floor}*

floor-->
split(y) {apt_width: partition}*

partition-->

split(z) {apt_depth: apt.}*

This is the rule I wrote for dividing a building into apartments. I want to add a boolean type attribute to each apartment. How do I do that? provide CGA rule for same.

0 Kudos
2 Replies
CherylLau
Esri Regular Contributor

If you can calculate the values of the attributes in the code, I would recommend creating one attribute and setting the value of this attribute for each apartment in the code using the set() operation.  The disadvantage of this approach is that you cannot see the attribute values for each apartment in the Inspector (because you can only see the attribute value for the whole building at the beginning of the rule).  The set() operation allows you to set the value of the attribute differently for different shapes in the shape tree.

set Operation 

One minor thing:  For an input footprint with dimensions in x and z, I would switch the axes for the x and y splits in your code.  Here's how you can add a boolean attribute isOccupied and set it for each apartment to a random true/false value.  Then, the apartment is colored green if the attribute is true and red if the attribute is false.

attr isOccupied = true

Lot -->
     extrude(height)
     split(y) { ~floor_height: Floor }*
     
Floor -->
     split(x) { ~apt_width: split(z) { ~apt_depth: Apartment }* }*
     
Apartment -->
     set(isOccupied, 50%: true else: false)
     ColoredApartment
     
ColoredApartment -->
     case isOccupied:
          color(0,1,0)
     else:
          color(1,0,0)
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Note that you could also do this without the attribute isOccupied by passing the random true/false value as parameters in the rules.

Lot -->
     extrude(height)
     split(y) { ~floor_height: Floor }*
     
Floor -->
     split(x) { ~apt_width: split(z) { ~apt_depth: Apartment(50%: true else: false) }* }*
     
Apartment(aptIsOccupied) -->
     case aptIsOccupied:
          color(0,1,0)
     else:
          color(1,0,0)

You could also pass values for the split indices if you need these values to calculate the values of the attribute.  Here, the attribute is set to true only for apartments with even numbered indices.

attr isOccupied = true

getVal_isOccupied(floor_index, col_index, row_index) =
     case floor_index%2==0 && col_index%2==0 && row_index%2==0:
          true
     else:
          false

Lot -->
     extrude(height)
     split(y) { ~floor_height: Floor(split.index) }*
     
Floor(floor_index) -->
     split(x) { ~apt_width: Column(floor_index, split.index) }*
     
Column(floor_index, col_index) -->
     split(z) { ~apt_depth: Apartment(floor_index, col_index, split.index) }*
     
Apartment(floor_index, col_index, row_index) -->
     set(isOccupied, getVal_isOccupied(floor_index, col_index, row_index))
     ColoredApartment
     
ColoredApartment -->
     case isOccupied:
          color(0,1,0)
     else:
          color(1,0,0)

If you want to set values in the Inspector, I would recommend using string lists to store the values for each apartment.  String lists are a set of strings separated by a semi-colon.  Go to the section "String List Utility Functions" on the main CGA reference page here for more info on what string functions are available:

CGA Reference Index 

SudarshanPokharkar
New Contributor

Thank You. It was quite useful.

0 Kudos