<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">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>Try something like this for your createIndex which will work with any collection of features:</div><div><br></div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">
def createIndex( features ):</div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"> index = QgsSpatialIndex()</div><div style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"> map(index.insertFeature, features)</div>
<div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"> return index</span> </div><div><br></div><div>index = <span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">createIndex(</span><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">provider.getFeatures())</span></div>
<div><br></div><div>and also because I hate seeing while nextFeature() used :)</div><div><br></div><div>- Nathan</div></div><br><br></div></div>