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

Casper Børgesen (CABO) CABO at NIRAS.DK
Thu Aug 11 05:27:00 PDT 2016


Hi Martin

Great and thanks for the heads up. I will look into QgsPointLocator and see if I can get it to work with better results :)

Regards, Casper

-----Original Message-----
From: Martin Dobias [mailto:wonder.sk at gmail.com] 
Sent: 11. august 2016 14:22
To: Casper Børgesen (CABO)
Cc: qgis-developer at lists.osgeo.org
Subject: Re: [Qgis-developer] Python: How to allow for more results using QgsSnapper.snapMapPoint(...)

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