Opened 17 years ago

Closed 16 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 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:
    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 17 years ago by ole

  • Description modified (diff)

comment:2 Changed 17 years ago by ole

  • Description modified (diff)

comment:3 Changed 17 years ago by ole

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

comment:4 Changed 17 years ago by ole

  • Description modified (diff)

comment:5 Changed 16 years ago by ole

  • Description modified (diff)

comment:6 Changed 16 years ago by ole

This was implemented in changeset:6129 as the new function

add_quantity()

with the same options as set_quantity.

comment:7 Changed 16 years ago by ole

  • Resolution set to fixed
  • Status changed from new to closed

This was documented in changeset:6131

Note: See TracTickets for help on using tickets.