Opened 16 years ago
Last modified 15 years ago
#250 closed enhancement
Extend set_quantity to allow addition of values — at Version 1
Reported by: | ole | Owned by: | ole |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | Architecture and API | Version: | |
Severity: | normal | Keywords: | |
Cc: |
Description (last modified by ole)
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:
#create new temporary quantity Q = Quantity(domain) Q.set_values(x)
quantities[quantity_name] += Q
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.