[Qgis-developer] Python: Select features that touch other features

Nathan Woodrow madmanwoo at gmail.com
Sat Oct 5 16:53:56 PDT 2013


On Sun, Oct 6, 2013 at 9:45 AM, Daniel <danielvaz at gmail.com> wrote:

> def createIndex( provider ):
>     feat = QgsFeature()
>     index = QgsSpatialIndex()
>     fit = provider.getFeatures()
>     while fit.nextFeature( feat ):
>         index.insertFeature( feat )
>     return index
>

Try something like this for your createIndex which will work with any
collection of features:

def createIndex( features ):
    index = QgsSpatialIndex()
    map(index.insertFeature, features)
    return index

index = createIndex(provider.getFeatures())

and also because I hate seeing while nextFeature() used :)

- Nathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20131006/f709a670/attachment-0001.html>


More information about the Qgis-developer mailing list