[Qgis-developer] Python: How to allow for more results using QgsSnapper.snapMapPoint(...)
Martin Dobias
wonder.sk at gmail.com
Thu Aug 11 09:09:53 PDT 2016
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