I want to enable the snapping options for the the existing layers using python programming. How can I do this?


I found a post here of someone who developed an Azimuth and Distance plugin which involved using snapping. You could take a look into the source code, it might lead you to the right direction.

Here is the script from the link posted:

def canvasPressEvent(self,event):
    if len(snapped[1])>0:
        #transforming pixels to x,y
        transform = self.canvas.getCoordinateTransform()
        xy = transform.toMapCoordinates(pixels) #captures the clicked coordinate and transform
    self.emit(SIGNAL("finished(PyQt_PyObject)"),xy)     #return QgsPoint in a signal
  • Thank you. But i want to enable snapping options before callling this trigger action. qgis.utils.iface.actionSplitFeatures().trigger() i dont want to link up with any events. Is there any possible way to do ? – user99 Feb 11 '15 at 9:34
  • When i am trying the following piece of code i am getting the following error: snapper = QgsMapCanvasSnapper(canvas) snapper.setSnapSettingsForLayer(aLayer,True,SnapToVertexAndSegment,pixels,0.0001,True) Traceback (most recent call last): File "<input>", line 1, in <module> AttributeError: 'QgsMapCanvasSnapper' object has no attribute 'setSnapSettingsForLayer' So how can i set the snapping to the layers? – user99 Feb 11 '15 at 12:08
  • Apologies but I am not experienced in this enough, hopefully others will advise. – Joseph Feb 12 '15 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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