[Qgis-developer] What's the recommended way to implement a spatial index in Processing algorithms?

Anita Graser anitagraser at gmx.at
Wed Jun 15 09:11:22 PDT 2016


​Hi,

On Tue, Jun 14, 2016 at 3:01 PM, Daan Goedkoop <dgoedkoop at 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 <volayaf at 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​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160615/d5f8c580/attachment-0001.html>


More information about the Qgis-developer mailing list