Skip to main content
Tweeted twitter.com/StackGIS/status/1380898380751241222
edited tags
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

How to get Getting X,Y coordinate with mouse click on the vertex of line feature withusing PyQGIS

How todo I 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 iI 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 )

How to get X,Y coordinate with mouse click on the vertex of line feature with PyQGIS

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 )

Getting X,Y coordinate with mouse click on vertex of line feature using PyQGIS

How do I 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 )
Source Link
Devenepali
  • 365
  • 2
  • 10

How to get X,Y coordinate with mouse click on the vertex of line feature with PyQGIS

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 )