1

I'm basically borrowing the code for picking up a coordinate from a mouse click from this answer :

How to programatically check for a mouse click in QGIS

However in a stand alone application I do not have access to iface, so am instead calling the class with :

tool = PointTool(self.map_canvas()) 
self.map_canvas().setMapTool(tool)

Intellisense finds the map_canvas ok and it compiles, but I am getting a run time error:

'QgsMapCanvas' object not callable

Any ideas why?

1
  • Hi, I have not had time to check if my understanding of this fixed the issue yet. I will look at it tomorrow. Thanks.
    – AnserGIS
    Jun 2, 2016 at 14:09

1 Answer 1

1

You don't mention if you're doing it, but as you're writing a standalone application, you need to create a Map Canvas by yourself, in this way:

self.map_canvas = QgsMapCanvas()

Then you can set the map tool using self.map_canvas:

tool = PointTool( self.map_canvas ) 
self.map_canvas.setMapTool( tool )

Why not to write the parenthesis in self.map_canvas?

Because you already have instantiated the QgsMapCanvas class, it's now an object and you don't call objects, you call methods or functions, such as iface.mapCanvas() (here you call a function of iface that returns the QGIS map canvas) or QgsMapCanvas() (here you call the constructor of the class, which is still a method).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.