[Qgis-developer] How to set up QgsPointLocator.MatchFilter in python?

Martin Dobias wonder.sk at gmail.com
Tue Mar 31 08:37:10 PDT 2015


Hi


On Fri, Mar 27, 2015 at 6:00 PM, luna <luna.helios at googlemail.com> wrote:

>
> Now I try to set up the MatchFilter to get matches only from a particular
> feature ID. But I don't know how to begin.


You need to implement your own MatchFilter subclass and pass it to one of
the functions that use it. For example, this is how to limit search to
feature id 5:

class FidFilter(QgsPointLocator.MatchFilter):
  def __init__(self, fid):
    QgsPointLocator.MatchFilter.__init__(self)
    self.fid = fid
  def acceptMatch(self, m):
    return m.featureId() == self.fid

m = locator.nearestVertex(QgsPoint(100,200), 10, FidFilter(5))


Cheers
Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150331/7b68a624/attachment-0001.html>


More information about the Qgis-developer mailing list