How to get X,Y coordinate with mouse click with enabling snapping so that only line's vertex point coordinates will be selected.
By using following code i can get latitude longitude of clicked position in map canvas of QGIS but cannot enable the snapping option .
from qgis.gui import QgsMapToolEmitPoint
class PrintClickedPoint(QgsMapToolEmitPoint):
def __init__(self, canvas):
self.canvas = canvas
QgsMapToolEmitPoint.__init__(self, self.canvas)
def canvasPressEvent( self, e ):
point = self.toMapCoordinates(self.canvas.mouseLastXY())
point = list(point)
iface.mapCanvas().snappingUtils().toggleEnabled()
print(point)
canvas_clicked = PrintClickedPoint( iface.mapCanvas() )
iface.mapCanvas().setMapTool( canvas_clicked )