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

Daniel danielvaz at gmail.com
Sat Oct 5 19:00:13 PDT 2013


Using map() is the pythonic way


Maybe ftools need an upgrade :)

Thanks for the tip


On Sat, Oct 5, 2013 at 8:53 PM, Nathan Woodrow <madmanwoo at gmail.com> wrote:

>
> 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
>
>
>


-- 
Daniel Vaz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20131005/1335e4f1/attachment.html>


More information about the Qgis-developer mailing list