Opened 18 years ago
Closed 17 years ago
#250 closed enhancement (fixed)
Extend set_quantity to allow addition of values
| Reported by: | ole | Owned by: | ole |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Architecture and API | Version: | |
| Severity: | normal | Keywords: | |
| Cc: |
Description (last modified by )
Sometimes, there is a need for adding values to a quantity - e.g. to put buildings on top of a landscape. Polygon_function is often used for defining the buildings, but there is currently no mechanism for adding them.
I suggest allowing a new boolean keyword, addition, in set_quantity so that one can say:
set_quantity('elevation', elevation_data
set_quantity('elevation', building_data, addition=True)
It would be easy to implement using the overloading of '+' already present in class Quantity. I suggest something like this if addition is True:
def set_quantity(quantity_name, x, addition=False):
...
if addition is True:
Q1 = domain.get_quantity(quantity_name)
Q2 = Quantity(domain) # Create new temporary quantity
Q2.set_values(x)
domain.set_quantity(quantity_name, Q1+Q2, addition=False)
or
domain.quantities[quantity_name] += Q2
Alternatively, we could make this behaviour the default as quantities are initialised as zero, and have a keyword 'replace'. On the other hand, this could be confusing whenever a code needs to change a quantity.
Change History (7)
comment:1 Changed 18 years ago by
| Description: | modified (diff) |
|---|
comment:2 Changed 18 years ago by
| Description: | modified (diff) |
|---|
comment:3 Changed 18 years ago by
comment:4 Changed 18 years ago by
| Description: | modified (diff) |
|---|
comment:5 Changed 17 years ago by
| Description: | modified (diff) |
|---|
comment:6 Changed 17 years ago by
This was implemented in changeset:6129 as the new function
add_quantity()
with the same options as set_quantity.
comment:7 Changed 17 years ago by
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
This was documented in changeset:6131

Probably call the keyword 'additive' rather than 'addition'.