Bug report #15421
QgsSnapper return only one result on multiple items
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | - | ||
Category: | PyQGIS Console | ||
Affected QGIS version: | master_2 | Regression?: | No |
Operating System: | windows | Easy fix?: | No |
Pull Request or Patch supplied: | No | Resolution: | end of life |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 23348 |
Description
Description:
I am trying to programmatically to snap to the nearest segment or segments. I have a layer with two lines (the corresponding SHAPE layer is attached):
- (0,0) -> (3,3)
- (1,1) -> (2,2)
These two lines has a common overlap corresponding to the second line.
Code:
I have set up the snapper as follows:
Setup the snap layer.
>>> sl = QgsSnapper.SnapLayer()
>>> sl.mLayer = iface.mapCanvas().currentLayer()
>>> sl.mTolerance = 25
>>> sl.mSnapTo = QgsSnapper.SnapToSegment
>>> sl.mUnitType = QgsTolerance.Pixels
Setup the snapper.
>>> sn = QgsSnapper(iface.mapCanvas().mapSettings())
>>> sn.setSnapLayers([sl])
I want more than one result if available.
>>> sn.setSnapMode = QgsSnapper.SnapWithResultsWithinTolerances
Snap using the center point of the common overlap - that should ensure both lines are detected.
>>> (retval, result) = sn.snapMapPoint(QgsPoint(1.5, 1.5))
The result, where I expect two items, but the following only gives me one.
>>> len(result)
1
According to https://github.com/qgis/QGIS/blob/master/src/core/qgssnapper.cpp#L108 using either QgsSnapper.SnapWithResultsForSamePosition
or QgsSnapper.SnapWithResultsWithinTolerances
should allow for more results.
What is going wrong for me here?
To reproduce:
- Open QGIS.
- Load the attached layer.
- Paste the above code into the Python console.
History
#1 Updated by Giovanni Manghi over 7 years ago
- Easy fix? set to No
- Regression? set to No
#2 Updated by Giovanni Manghi over 5 years ago
- Resolution set to end of life
- Status changed from Open to Closed
End of life notice: QGIS 2.18 LTR
Source:
http://blog.qgis.org/2019/03/09/end-of-life-notice-qgis-2-18-ltr/