I have two layers with the same feature ("Object ID") and same location

  • All lightning strikes
  • Cloud strikes

I want to delete the 'Cloud strikes' that are still to be found in the 'All lightning strikes' based on the location or the same "Object ID". How can I do that?

Notice, these duplicates are NOT in the same vector layers, so I cannot use v.clean or Remove Duplicates as they only take one layer into account.

And, I do not want to merge the files and then delete as my QGIS messes up my layer projection.

Edit: The layers are the same projection, and the "Object ID"s are features in both attribute tables.

  • Two questions: Are the two layers in the same projection? Do you see Object ID as a field in the attribute tables? – MortenSickel Mar 18 '20 at 11:34
  • To find duplicate ids, join the tables, select by attributes where there is a match. – BERA Mar 18 '20 at 12:25
  • @MortenSickel, yes and yes. See my edits. Thank you. – Thomas Mar 18 '20 at 12:48

If your "object id"s are fields that can be read by qgsFeature.attribute(), this should work to mark all items in "Cloud strikes" that have the "Object ID" in "All lightning strikes"

selectlayername='All lightning strikes'
fieldname='Object ID'
filterlayername='Cloud strikes'

sellayer = QgsProject.instance().mapLayersByName(selectlayername)[0]

for f in sellayer.getFeatures():

filterlayer = QgsProject.instance().mapLayersByName(filterlayername)[0]

for f in filterlayer.getFeatures():
    if f.attribute(fieldname) in items:


In case there are more layers with the same names, the first one will be selected.

This does not delete the points as you asked for, but when the points are selected, you can delete them afterwards (I prefer doing it like that to make sure that the automatic selection makes sense)

If you still have some strikes you want to get rid of being at the same spot, you need to do an overlay - or you may rewrite my script to do a selection on coordinates (and possible time?) or other relevant parameters that define a strike.

  • 1
    Would the person who downvoted please explain what is the problem? – MortenSickel Mar 18 '20 at 13:33

Thank you for the useful feedback. I ended up selecting the overlapping points by using the tool Select by location

  • I selected features in All Lightning Strikes
  • Based on the points in both layers being equal
  • From the features in Cloud Strikes

It took some time and computation, however, the result was what I needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.