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

Transforming attributes of csv-based layers causes the plugin to break #253

Open ptormene opened 7 years ago

ptormene commented 7 years ago

For instance, if you try to transform an attribute of a csv-based layer, the plugin breaks with the following error:

  File "/home/paolo/.qgis2/python/plugins/svir/irmt.py", line 1297, in transform_attributes
    target_attr_alias)
  File "/home/paolo/.qgis2/python/plugins/svir/calculations/process_layer.py", line 333, in transform_attribute
    attr_names_dict = self.add_attributes([field], simulate=simulate)
  File "/home/paolo/.qgis2/python/plugins/svir/calculations/process_layer.py", line 220, in add_attributes
    proposed_attribute_list)
AttributeError: Unable to add attributes []

The plugin should suggest to save the layer into a different format in which it is possible to edit fields, before attempting to perform the field transformation.

ptormene commented 7 years ago

The error message is now much clearer:

Traceback (most recent call last):
  File "/home/paolo/.qgis2/python/plugins/svir/dialogs/transformation_dialog.py", line 182, in update_default_fieldname
    inverse, simulate=True)
  File "/home/paolo/.qgis2/python/plugins/svir/calculations/process_layer.py", line 299, in transform_attribute
    ' its attributes.' % self.layer.providerType())
TypeError: Unable to edit features of this kind of layer (delimitedtext). Please consider saving the layer with an editable format before attempting to transform its attributes.

It would be even better to trap the exception and display the error message in the QGIS message bar,