Hi, On Tue, Jun 14, 2016 at 3:01 PM, Daan Goedkoop <dgoedk...@gmail.com> wrote:
> What I use is: > features = processing.features( layer ) > index = QgsSpatialIndex( features.__iter__() ) Thanks Daan, that looks good! On Wed, Jun 15, 2016 at 12:31 PM, Victor Olaya <vola...@gmail.com> wrote: > i guess that the spatial index should be created as usual, but, as you > say, only including selected features if the Processing settings is > configured to use only those ones. > I dont see any specific thing about it being a Processing algorithm, > other than that. An even if you create it for the whole layer, it > should be fine (although less efficient) > > 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 ... > Any particular problem that you are facing with this > ? > 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.) Best wishes, Anita
_______________________________________________ Qgis-developer mailing list Qgis-developer@lists.osgeo.org List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer