I am trying to find all points in a vector layer that do not have a duplicate point.
To do this, for each point I create a list of features that intersect its bounding box ('candidates') then check if any candidate is an exact geometry match. I've included the exact code below.
However, no matter how I tweak the code I don't end up with any duplicate points. I know for a fact there are many duplicate points (various topology checks and knowledge of dataset) so there's something wrong.
Is this an issue with using the bounding box, or another part of my code?
I'm using Python because every existing tool I've found only flags duplicates, but tool suggestions are fine too.
Working with QGIS 3.4x64 and Python 3.7 on Windows 10.
geoms = {} # { vertex id : geom }
for v in point_layer.getFeatures():
if not v.hasGeometry():
continue
geoms[v.id()] = v.geometry()
index = QgsSpatialIndex()
no_dup = [] #list of vertex IDs with no duplicates
for v_id, geometry in geoms.items():
candidates = index.intersects(geometry.boundingBox())
duplicates = []
for candidate_id in candidates:
if geometry.isGeosEqual(geoms[candidate_id]):
duplicates.append(v_id)
if len(duplicates) == 1: #only one point in location
no_dup.append(v_id)
Note: I considered creating a buffer instead of using the boundary box but I have over 100k features and would prefer not to create another layer