1

I have a vector polygon and vector polyline layer. I want to enable the snapping for both the layer with tolerance value? How can i do that using python programming. I have tried this code but getting the following error:

snapper = QgsMapCanvasSnapper(canvas) 
snapper.setSnapSettingsForLayer(aLayer,True,SnapToVertexAndSegment,pixels,0.0001‌​,True) 

Traceback (most recent call last): File "", line 1, in AttributeError: 'QgsMapCanvasSnapper' object has no attribute 'setSnapSettingsForLayer'

Can anyone help me in setting the snapping options to the currentLayer using python programming?

2

You must define it first:

result3 = QgsVectorLayer("LineString", "ligne", "memory") 
#it's to create your layer

ligneid=result3.id()
# it allows you to have the idvalue for your layer

QgsProject.instance().setSnapSettingsForLayer(ligneid,True,2,1,1000,True)
# it defines the snapping options ligneid : the id of your layer, True : to enable the layer snapping, 2 : options (0: on vertex, 1 on segment, 2: vertex+segment), 1: pixel (0: type of unit on map), 1000 : tolerance, true : avoidIntersection)

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.