Feature request #15012

Hub Distance should use spatial index

Added by Anita Graser 10 months ago. Updated 9 months ago.

Status:Closed Start Date:06/12/2016
Priority:Normal Due date:
Assigned to:Victor Olaya % Done:

0%

Category:Processing/QGIS
Target version:Future Release - Nice to have
Platform: Resolution:
Platform version: Pull Request or Patch supplied:No
Status info: Tag:

Description

Hub distance in Processing (https://github.com/qgis/QGIS/blob/master/python/plugins/processing/algs/qgis/HubDistance.py) is very slow because it does not take advantage of spatial indexing.

Associated revisions

Revision e0c9733f6482f184aeeff1339fafef210d1a0709
Added by Alexander Bruy 9 months ago

[processing] speedup Hub distance algorithm (fix #15012)

Revision c5e7a9810affd2a6648caa93db39b3082eb6bc82
Added by Alexander Bruy 9 months ago

[processing] speedup Hub distance algorithm (fix #15012)

(cherry picked from commit e0c9733f6482f184aeeff1339fafef210d1a0709)

Conflicts:
python/plugins/processing/algs/qgis/HubDistance.py

History

Updated by Anita Graser 10 months ago

What's the best way to use a spatial index in a Processing script?

This does not take selection and layer filters into account:

index = QgsSpatialIndex(layerHubs.getFeatures())

Updated by Nyall Dawson 10 months ago

Anita - what do you mean by "layer filters"?

Updated by Anita Graser 10 months ago

Hi Nyall, I meant the layer's "provider feature filter" is ignored by layer.getFeatures(). (Btw, I don't think this was always the case in the past.)

Updated by Nyall Dawson 10 months ago

Anita - I can't reproduce that. What's the data source? It's definitely a bug and it should be respected, and there's a even a bunch of unit tests to ensure that...

Updated by Anita Graser 10 months ago

Sorry, I got something wrong here. Will open a new ticket when I find the source of my issue ... I had some issue mixing

processing.tools.vector.features(layer)

and

layer.getFeatures()

...

Anyway, back to the main topic: What's the recommended way to implement a spatial index in Processing algorithms?

Updated by Nyall Dawson 10 months ago

I'd just do (psuedocode)

If using selected features:
index = QgsSpatialIndex(layerHubs.selectedFeaturesIterator())
Else:
index = QgsSpatialIndex(layerHubs.getFeatures())

Updated by Alexander Bruy 9 months ago

  • Status changed from Open to Closed

Also available in: Atom