-
Notifications
You must be signed in to change notification settings - Fork 3
Dev notes
Sergio Botero edited this page Mar 12, 2014
·
1 revision
A cool feature on the QGIS API is the QgsSpatialIndex. I tried to use it but it does not work for us.
index = QgsSpatialIndex()
for feature in provider.getFeatures(): # feature as each area with its geometry
index.insertFeature(feature)
Now using the index.intersects(feature.geometry())
(and you can add a buffer to the geometry with feature.geometry().buffer(10, 2)
) we get a list of features that intersect with the geometry of the feature we are testing. The Problem with this is that the geometry used are bounding boxes and when having map and irregular shapes, an intersection can show neighbors that are not spatial neighbors.
If there is a way to avoid this kind of errors while using the Spatial Index, would be a good alternative since the use of it really seems to speed up the implementation.
A good post on using the Spatial Index here