[Qgis-developer] Python: How to allow for more results using QgsSnapper.snapMapPoint(...)

Martin Dobias wonder.sk at gmail.com
Thu Aug 11 05:22:28 PDT 2016


Hi Casper

On Tue, Aug 9, 2016 at 6:34 PM, Casper Børgesen (CABO) <CABO at niras.dk> wrote:
> I’m playing around with the QGIS (d01bfd1) snap functionalities in python
> and I’m trying to get it return all the segments in the vicinity of the
> point of interest.

Instead of using QgsSnapper classes, try QgsPointLocator. The old
snapping classes around QgsSnapper will be removed in QGIS 3.0 as they
have been replaced by QgsPointLocator and QgsSnappingUtils anyway -
the new classes perform better and they are easier to use. They are
available in API since QGIS 2.8.

The following should work for you to get all segments in vicinity:

loc = QgsPointLocator(canvas.currentLayer())
results = loc.edgesInRect(QgsPoint(2.0, 2.0), 0.5)

The "results" variable will contain matches with all edges around
given point with specified tolerance.

Regards
Martin


More information about the Qgis-developer mailing list