Conditional and FromStyleBlockAttr
Closed this issue · 13 comments
claddingMaterial = PerBuilding(Value(Alternatives(
FromAttr("roof:material", FromAttr.String, CladdingMaterials),
Conditional(
lambda roof: roof.footprint.getStyleBlockAttr("roofShape") == "flat",
RandomWeighted(( ("concrete", 1), ("gravel", 1) ))
),
Conditional(
lambda roof: roof.footprint.getStyleBlockAttr("roofShape") == "dome",
Constant("glass")
),
FromStyleBlockAttr("claddingMaterial", FromStyleBlockAttr.Footprint)
)))
Condtional
has to arguments:
- a condition
- a value
It returns the value if the conditions is True, otherwise it returns None.
It can be represented in PML as:
claddingMaterial:
FromAttr("roof:material") |
RandomWeighted( ("concrete", 1), ("gravel", 1) ) if item.footprint["roofShape"] == "flat" |
glass if item.footprint["roofShape"] == "dome" |
item.footprint["claddingMaterial"]
;
How to represent it in blosm nodes?
Conditional node
Input sockets:
- condition
- value
Output sockets:
- value
From Style Block node
Input sockets:
no
Output sockets:
- value
Properties:
- item (a choice between "self", "footprint" and "parent")
- attribute (a list of popular style block attributes)
From OSM node
Input sockets:
no
Output sockets:
- value
Properties:
- OSM tag (a long list of the popular OSM tags)
Alternatives node
Input sockets (probably 7 values is enough):
- value 1
- value 2
- value 3
- value 4
- value 5
- value 6
- value 7
Output sockets:
- value
How to represent it in blosm nodes?
FromAttr("roof:material", FromAttr.String, CladdingMaterials),
From OSM
.value
-> Alternatives
.value 1
Conditional(
lambda roof: roof.footprint.getStyleBlockAttr("roofShape") == "flat",
RandomWeighted(( ("concrete", 1), ("gravel", 1) ))
),
RandomWeighted
.value
-> Conditional
.value
Conditional
.value
-> Alternatives
.value 2
Conditional(
lambda roof: roof.footprint.getStyleBlockAttr("roofShape") == "dome",
Constant("glass")
),
)))
CladdingMaterial
.value -> Conditional
.value
Conditional
.value
-> Alternatives
.value 3
FromStyleBlockAttr("claddingMaterial", FromStyleBlockAttr.Footprint)
From Style Block
.value
-> Alternatives
.value 4
And finally:
Alternatives
.value
-> Roof
.claddingMaterial
Per Building node
Input sockets:
- value
Output sockets:
- value
Per Footprint node
Input sockets:
- value
Output sockets:
- value
I do not really understand the term item in the condition. The proposition in PML is
glass if item.footprint["roofShape"] == "dome"
while the corrsponding Python code becomes
Conditional(
lambda roof: roof.footprint.getStyleBlockAttr("roofShape") == "dome",
Constant("glass")
),
How can a translator find that the item is roof here? Where does this context come from?
Any variable can be used in the Python's lambda syntax:
lambda anything: anything is None
I'd suggest always use the variable item in the Python code.
To be continued at prochitecture/pml#6