[Qgis-developer] Python: How to allow for more results using QgsSnapper.snapMapPoint(...)
Casper Børgesen (CABO)
CABO at NIRAS.DK
Thu Aug 11 06:31:29 PDT 2016
Hi Martin
My goal was to use the snapping functionality to snap to the nearest edges/vertices and when a snap occurred I would evaluate the features involved in the snap. If two or more edges where equally close (ex. on top of each other) I needed to remember which ones it was.
Using the methods of QgsSnappingUtils I only get one match back. Is it possible to get all the matches back or do I need to use the QgsPointLocater afterwards to determine if I was snapping to more than one feature? I see no reason to make two lookups if the results I'm looking for is available already.
Regards, Casper
-----Original Message-----
From: Qgis-developer [mailto:qgis-developer-bounces at lists.osgeo.org] On Behalf Of Casper Børgesen (CABO)
Sent: 11. august 2016 14:27
To: Martin Dobias
Cc: qgis-developer at lists.osgeo.org
Subject: Re: [Qgis-developer] Python: How to allow for more results using QgsSnapper.snapMapPoint(...)
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
_______________________________________________
Qgis-developer mailing list
Qgis-developer at lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
More information about the Qgis-developer
mailing list