[Qgis-developer] Python: How to allow for more results using QgsSnapper.snapMapPoint(...)
Casper Børgesen (CABO)
CABO at NIRAS.DK
Fri Aug 12 01:02:17 PDT 2016
Hi Martin
Thanks for the reference to your nodetool and the concept works great for me. Its cool to know about the locators cache too. I have always thought of filters as being an object for the method to use and not an object which can collect and afterwards return information. My mind is expanding...
Hopefully I'm now a step closer to being QGIS 3.0 compliant :)
Regards, Casper
-----Original Message-----
From: Martin Dobias [mailto:wonder.sk at gmail.com]
Sent: 11. august 2016 18:10
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(...)
On Thu, Aug 11, 2016 at 3:31 PM, Casper Børgesen (CABO) <CABO at niras.dk> wrote:
> 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.
There are more way how to do it - one as you say would be to check with individual QgsPointLocator instances. Internally the locators build their cache, so subsequent calls are fast anyway.
The other option would be to use QgsSnappingUtils::snapToMap() with a custom filter (an optional argument in various QgsSnappingUtils and QgsPointLocator methods). Your filter does not need to filter out any matches, but instead it can collect any relevant matches that would not be returned otherwise. See for example here [1].
Cheers
Martin
[1] https://github.com/wonder-sk/CadNodeTool/blob/master/nodetool.py#L513
More information about the Qgis-developer
mailing list