I'm trying to build a plugin that firstly captures the map coordinates.
I have tried to adapt the map tool explained in this post: How to programatically check for a mouse click in QGIS
The code I used for the main function is below:
def canvasReleaseEvent(self, event):
#Get the click
x = event.pos().x()
y = event.pos().y()
canvas = self.canvas
canvas.mapRenderer().setProjectionsEnabled(True)
canvas.mapRenderer().setDestinationCrs(QgsCoordinateReferenceSystem(27700))
espg = canvas.mapRenderer().destinationCrs().authid()
point = self.canvas.getCoordinateTransform().toMapCoordinates(x, y)
Unfortunately the when I print point it always returns as (0,0). I have tried various ways to set the crs of the points but none work. What needs to be done to make it work?
QgsCoordinateTransformif you need to transform from one to the other, or justtoMapCoordinatesis enough to go from click to canvas coordinates – Nathan W Aug 09 '14 at 11:14