I have a lot of coordinates in attribute table like this one:
I'm looking the way how to find and select on active layer duplicated points using Python in QGIS ? I needn't delete them but only find and show (or select).
Answer
This code should do the job (you need to have your layer activated before running it from the Python Console):
layer = iface.activeLayer()
allfeatures={}
index = QgsSpatialIndex()
for ft in layer.getFeatures():
allfeatures[ft.id()] = ft
index.insertFeature(ft)
selection = []
for feat in layer.getFeatures():
inGeom = feat.geometry()
idsList = index.intersects(inGeom.boundingBox())
if len(idsList) > 1:
for id in idsList:
selection.append(allfeatures[id])
layer.setSelectedFeatures([k.id() for k in selection])
No comments:
Post a Comment