gem / oq-irmt-qgis

QGIS plugin to drive the OpenQuake Engine, to develop Social Vulnerability and Integrated Risk composite indices, and to predict building recovery times following an earthquake
https://plugins.qgis.org/plugins/svir/
8 stars 3 forks source link

Error using custom field in weighting tree (both in QGIS2 and QGIS3) #470

Open ptormene opened 6 years ago

ptormene commented 6 years ago

It happens when attempting to use a custom field but no field is available to save the calculated value. If, on the contrary, an available field exists, it is possible to select it, and it works.

TypeError: fieldNameIndex(self, str): argument 1 has unexpected type 'QPyNullVariant' 
Traceback (most recent call last):
  File "/home/paolo/.qgis2/python/plugins/svir/irmt.py", line 880, in 
    dlg.json_cleaned.connect(lambda data: self._weights_changed(data, dlg))
  File "/home/paolo/.qgis2/python/plugins/svir/irmt.py", line 939, in _weights_changed
    self._recalculate_indexes(data)
  File "/home/paolo/.qgis2/python/plugins/svir/irmt.py", line 970, in _recalculate_indexes
    self.iface, self.iface.activeLayer(), svi_node)
  File "/home/paolo/.qgis2/python/plugins/svir/calculations/calculate_utils.py", line 137, in calculate_composite_variable
    get_node_attr_id_and_name(edited_node, layer)
  File "/home/paolo/.qgis2/python/plugins/svir/calculations/calculate_utils.py", line 184, in get_node_attr_id_and_name
    if layer.fieldNameIndex(node_attr_name) == -1:  # not found
TypeError: fieldNameIndex(self, str): argument 1 has unexpected type 'QPyNullVariant'
ptormene commented 5 years ago

We might keep the option to use a custom operator and, if no field is available, a new field could be created to store the composite index