Feature request #15012

Hub Distance should use spatial index

Added by Anita Graser 12 months ago. Updated 11 months ago.

Status:Closed
Priority:Normal
Assignee:Victor Olaya
Category:Processing/QGIS
Pull Request or Patch supplied:No Resolution:
Easy fix?:No

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 e0c9733f
Added by Alexander Bruy 11 months ago

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

Revision c5e7a981
Added by Alexander Bruy 11 months ago

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

(cherry picked from commit e0c9733f6482f184aeeff1339fafef210d1a0709)

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

History

#1 Updated by Anita Graser 12 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())

#2 Updated by Nyall Dawson 12 months ago

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

#3 Updated by Anita Graser 11 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.)

#4 Updated by Nyall Dawson 11 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...

#5 Updated by Anita Graser 11 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?

#6 Updated by Nyall Dawson 11 months ago

I'd just do (psuedocode)

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

#7 Updated by Alexander Bruy 11 months ago

  • Status changed from Open to Closed

Also available in: Atom PDF