<div dir="ltr"><div class="gmail_default" style="font-size:small"><div class="gmail_default">​Hi,</div><br><div class="gmail_quote">On Tue, Jun 14, 2016 at 3:01 PM, Daan Goedkoop <span dir="ltr"><<a href="mailto:dgoedkoop@gmail.com" target="_blank">dgoedkoop@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">What I use is:<br>features = processing.features( layer )<br>index = QgsSpatialIndex( features.__iter__() )</blockquote><div><br></div><div>Thanks Daan, that looks good!</div><div> </div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 15, 2016 at 12:31 PM, Victor Olaya <span dir="ltr"><<a href="mailto:volayaf@gmail.com" target="_blank">volayaf@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">i guess that the spatial index should be created as usual, but, as you<br>
say, only including selected features if the Processing settings is<br>
configured to use only those ones.<br>
I dont see any specific thing about it being a Processing algorithm,<br>
other than that. An even if you create it for the whole layer, it<br>
should be fine (although less efficient)<div class="gmail_default" style="font-size:small;display:inline">​​</div></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">​Well, it would be less efficient to build the index and one would have to check later on if the feature was selected. Otherwise, e.g. the hub distance algorithm, would return wrong matches to unselected hubs ...</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
Any particular problem that you are facing with this<div class="gmail_default" style="font-size:small;display:inline">​?</div></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">​No particular problem, just wondering what's the most elegant way and if there is anything I should be aware of when implementing the index. It would be good to have this as an example in the PyQGIS Cookbook imho. (Not just building the index but also accessing the nearest features.)</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Best wishes,</div><div class="gmail_default" style="font-size:small">Anita​</div><br></div><div><br></div></div></div></div>