ccrook / QGIS-VectorFieldRenderer-Plugin

QGIS python plugin for rendering vector field data as arrows, optionally with error ellipse
11 stars 4 forks source link

AttributeError: 'QgsFeatureRendererV2' object has no attribute ... #4

Closed ccrook closed 8 years ago

ccrook commented 10 years ago

Error occurs on platforms which do not allow setting the renderer via the properties dialog (this rendererer does not implement a graphical user interface #2) Although the fix to this issue allows the renderer to be assigned to a layer, it is unfortunately virtually useless, as the same underlying issue means that the buttons for setting the layer properties etc all generate the an error along the lines of

AttributeError: 'QgsFeatureRendererV2' object has no attribute ...

This is because the python bindings for the renderer are lost when it is passed via a C++ base class object (QgsFeatureRendererV2).

http://hub.qgis.org/issues/8646

jferencik commented 8 years ago

This is a hack but I managed to overcome this by creating an instance attribute dictionary in the VectorFieldRendererController.py's constuctor from time import time

def init( self, iface ): self.vlayers = {}

and store inside the renderer for any given layer the renderer instance retrived from VectorFieldRendererLayerDialog instance inside showLayerDialog method

def showLayerDialog( self ): layer, renderer = self.findRenderer() dialog=VectorFieldRendererLayerDialog( layer, renderer ) rendererid = '{0}{1}'.format(layer.name, str(int(time()))) layer.renderer_id = renderer_id self.vlayers[rendererid] = dialog.widget.r if dialog.exec() == QDialog.Accepted: self.refreshLayer(layer)

then in case the name of the renderer name is correct but the instance is not fetch the renderer from the dictioanary instead from C++ pi

def renderStarting( self ): for l,r in self.vectorRendererLayers(): if hasattr(l, 'renderer_id') and not isinstance(r, VectorFieldRenderer): r = self.vlayers[l.renderer_id] if r.getGroupScale(): l.triggerRepaint()

ccrook commented 8 years ago

@jferencik Thanks for input to this ... I'll try and look at this over the next week or so and get back to you...

rfsleal commented 8 years ago

Hi there:

This issue 's been quiet for a while. Don't know if this (very useful to me, at least) plugin is still maintained. For the record, @jferencik 's hack works on my system.

QGIS: 2.16.1-Nødebo
Compiled against Qt
4.8.6
Running against Qt
4.8.6
Compiled against GDAL/OGR
2.1.0
Running against GDAL/OGR
2.1.0
Compiled against GEOS
3.5.0-CAPI-1.9.0
Running against GEOS
3.5.0-CAPI-1.9.0 r4084
PostgreSQL Client Version
9.4.5
SpatiaLite Version
4.3.0a
QWT Version
5.2.3
PROJ.4 Version
492
QScintilla2 Version
2.9

Running on a openSUSE 42.1 x86_64 laptop.
ccrook commented 8 years ago

Hi @rfsleal - thanks for the reminder.

Maintained but too much other stuff intruding and just haven't been able to get back to it. Had hoped to find a good solution but a "hack" is much better than no solution - so will incorporate this and release for now.

ccrook commented 8 years ago

I've adapted @jferencik approach and also addressed some other issues that have arisen in the plugin (eg not being able to change the settings in QGIS 2.16). Hopefully I have not lost the fix from jferencik in my adaptation.

The update is version 3.5.2. @rfsleal - would be great if you could confirm whether or not this version fixes your issue.

rfsleal commented 8 years ago

Upgrading to 3.5.2 fixes the thread's issue but throws a different error:

An error has occurred while executing Python code: 

TypeError: 'NoneType' object is not callable 
Traceback (most recent call last):
  File "/home/rleal/.qgis2/python/plugins/VectorFieldRenderer/VectorFieldRenderer.py", line 259, in clone
TypeError: 'NoneType' object is not callable

Python version: 2.7.12 (default, Jul 01 2016, 15:34:22) [GCC] 
QGIS version: 2.16.1-Nødebo Nødebo, exported
ccrook commented 8 years ago

@rfsleal. Can you advise steps to reproduce this error.

I'm running a similar system (Ubuntu 14.04, same version of QGIS and Qt - slightly older of other components but they are not involved), and as yet have not encountered this error. The line referenced in the error message (259) does not have any code, it is a blank line before the beginning of the clone function, which is odd. Could you do a checksum to confirm that the plugin has installed correctly?

> cd ~/.qgis2/python/plugins/VectorFieldRenderer
> cksum *.py
1601364382 1008 __init__.py
467711041 45461 Ui_VectorFieldRendererWidget.py
3077499156 12042 Ui_VectorScaleBoxOptionsDialog.py
1667532642 24184 VectorArrowMarker.py
1121253299 10414 VectorFieldRendererController.py
424826159 1150 VectorFieldRendererLayerDialog.py
2950161388 985 VectorFieldRendererMetadata.py
444533728 1217 VectorFieldRendererPlugin.py
1097907280 24119 VectorFieldRenderer.py
898393683 23071 VectorFieldRendererResources.py
3510373581 15441 VectorFieldRendererWidget.py
3074786891 3324 VectorScaleBoxOptionsDialog.py
432336465 1779 VectorScaleBoxPluginLayer.py
3237007694 11381 VectorScaleBox.py
rfsleal commented 8 years ago

Hi:

Did a reinstall and verified the checksum. Seems OK:

rleal@papyro:~/.qgis2/python/plugins/VectorFieldRenderer> cksum *.py
1601364382 1008 __init__.py
467711041 45461 Ui_VectorFieldRendererWidget.py
3077499156 12042 Ui_VectorScaleBoxOptionsDialog.py
1667532642 24184 VectorArrowMarker.py
1121253299 10414 VectorFieldRendererController.py
424826159 1150 VectorFieldRendererLayerDialog.py
2950161388 985 VectorFieldRendererMetadata.py
444533728 1217 VectorFieldRendererPlugin.py
1097907280 24119 VectorFieldRenderer.py
898393683 23071 VectorFieldRendererResources.py
3510373581 15441 VectorFieldRendererWidget.py
3074786891 3324 VectorScaleBoxOptionsDialog.py
432336465 1779 VectorScaleBoxPluginLayer.py
3237007694 11381 VectorScaleBox.py

I don't get that complaint anymore (probably was a conflicting file or similar) and I can visualize older VFR layers. However layer edit (these were created as polar vector field types) is not possible due to an error before the gui is initialized:

2016-09-08T12:57:34 1   Traceback (most recent call last):
              File "/home/rleal/.qgis2/python/plugins/VectorFieldRenderer/VectorFieldRendererController.py", line 246, in showLayerDialog
                dialog=VectorFieldRendererLayerDialog( layer, renderer, self )
              File "/home/rleal/.qgis2/python/plugins/VectorFieldRenderer/VectorFieldRendererLayerDialog.py", line 23, in __init__
                self.widget.uCrashWarning.hide()
            AttributeError: 'VectorFieldRendererWidget' object has no attribute 'uCrashWarning'

Or like this:

An error has occurred while executing Python code: 

UnboundLocalError: local variable 'fields' referenced before assignment 
Traceback (most recent call last):
  File "/home/rleal/.qgis2/python/plugins/VectorFieldRenderer/VectorFieldRendererController.py", line 246, in showLayerDialog
    dialog=VectorFieldRendererLayerDialog( layer, renderer, self )
  File "/home/rleal/.qgis2/python/plugins/VectorFieldRenderer/VectorFieldRendererLayerDialog.py", line 22, in __init__
    self.widget=VectorFieldRendererWidget(layer,self.stylev2,renderer,controller)
  File "/home/rleal/.qgis2/python/plugins/VectorFieldRenderer/VectorFieldRendererWidget.py", line 80, in __init__
    self.loadFromRenderer()
  File "/home/rleal/.qgis2/python/plugins/VectorFieldRenderer/VectorFieldRendererWidget.py", line 246, in loadFromRenderer
    self.setMode( vfr.mode())
  File "/home/rleal/.qgis2/python/plugins/VectorFieldRenderer/VectorFieldRendererWidget.py", line 153, in setMode
    nfields=len(fields)
UnboundLocalError: local variable 'fields' referenced before assignment

If I try to create a new polar vector field type layer, it throws the same error. Other VF types work flawlessly.

Hope this helps locating the issue.

ccrook commented 8 years ago

@rfsleal Should be fixed in 3.5.3 ....

rfsleal commented 8 years ago

Yes!! Thnks.

ccrook commented 8 years ago

Closing - latest update appears to have fixed (worked around?) this issue.