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): pixels=event.pos() snapper=QgsMapCanvasSnapper(self.canvas) snapped=snapper.snapToBackgroundLayers(pixels) if len(snapped)>0: xy=snapped.afterVertex else: #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