<div dir="ltr"><div>Using map() is the pythonic way</div><div><br></div><div><br></div>Maybe ftools need an upgrade :)<div><br></div><div>Thanks for the tip</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Sat, Oct 5, 2013 at 8:53 PM, Nathan Woodrow <span dir="ltr"><<a href="mailto:madmanwoo@gmail.com" target="_blank">madmanwoo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote"><div class="im">On Sun, Oct 6, 2013 at 9:45 AM, Daniel <span dir="ltr"><<a href="mailto:danielvaz@gmail.com" target="_blank">danielvaz@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>def createIndex( provider ):</div><div> feat = QgsFeature()</div>
<div> index = QgsSpatialIndex()</div><div> fit = provider.getFeatures()</div><div> while fit.nextFeature( feat ):</div><div> index.insertFeature( feat )</div>
<div> return index</div></blockquote><div><br></div></div><div>Try something like this for your createIndex which will work with any collection of features:</div><div><br></div><div style="font-size:13px;font-family:arial,sans-serif">
def createIndex( features ):</div><div style="font-size:13px;font-family:arial,sans-serif"> index = QgsSpatialIndex()</div><div style="font-size:13px;font-family:arial,sans-serif"> map(index.insertFeature, features)</div>
<div><span style="font-size:13px;font-family:arial,sans-serif"> return index</span> </div><div><br></div><div>index = <span style="font-size:13px;font-family:arial,sans-serif">createIndex(</span><span style="font-size:13px;font-family:arial,sans-serif">provider.getFeatures())</span></div>
<div><br></div><div>and also because I hate seeing while nextFeature() used :)</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>- Nathan</div></font></span></div><br><br></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Daniel Vaz
</div>