I am trying to select a feature from the layer using my plugin. When working with my plugin in main Python function using QGIS, I receive an AttributeError when I call a class method from within the class itself.
I'm using QGIS 2.8.
Here is my code below:
def handle_mouse_down(point):
""""Manage selection when clicking on the canvas."""
layer = iface.activeLayer()
canvas = iface.mapCanvas()
layers = canvas.layers()
clickTool = QgsMapToolEmitPoint(canvas)
vl_to_query = [l for l in layers if l.name() != u'my_layer_name'][0]
w = canvas.mapUnitsPerPixel() * 3
rect = QgsRectangle(
point.x() - w,
point.y() - w,
point.x() + w,
point.y() + w
)
l_rect = canvas.mapSettings().mapToLayerCoordinates(vl_to_query, rect)
vl_to_query.select(l_rect, False)
feats = vl_to_query.selectedFeatures()
vl_to_query.removeSelection()
clickTool.canvasClicked.disconnect(self.handle_mouse_down)
When I run this function am getting an error like
File "C:/Users/.qgis2/python/plugins\Myclass\Myclass.py", line 220, in handle_mouse_down point.x() - w,
AttributeError: Myclass instance has no attribute 'x'
point = Myclass()somewhere in your code and Myclass has no attributex. It's hard to tell what problem is just by looking at this part of yourMyclass.pyfile. How do you callhandle_mouse_down()method and pass the argument. Did you definexattribute forMyclassclass or inherit from any class which has attributex? – Kadir Şahbaz Aug 07 '18 at 06:45