5

How do I delete features with identical table attributes in QGIS? Otherwise, is there a tool like the 'Delete Identical Tool' in ArcGIS?

For example, if I had 4 rows, and 3 columns, where I wanted to delete identical features based on 2 columns:

id value 1 value 2
1 A m
2 A m
3 A p
4 B m

I want it to be reduced to only 1 feature for each identical set of attributes:

id value 1 value 2
1 A m
3 A p
4 B m

In ArcGIS Desktop, this is a simple tool shown below called 'Delete Identical', where I can select one or more columns at the same time. I use this tool all the time, am switching to QGIS.

arcgis

3
  • 1
    I posted this elsewhere in Stackoverflow, and it got downvoted -1 with no explanation. If you downvote, can you please tell me why??
    – nittyjee
    Nov 10, 2018 at 7:11
  • 1
    Always some lamers downvoting there. Maybe because you havent attempted anything on your own
    – BERA
    Mar 24, 2021 at 7:48
  • 1
    @BERA, you are so right!
    – Taras
    Mar 24, 2021 at 7:51

3 Answers 3

10

For future reference: the next version of QGIS (3.6) includes a built-in 'Delete duplicates by attribute' tool which does exactly this.

2
  • I am looking for something similar, but it should delete the feature with a minimal value of an attribute. For example, I have two lines with same name, I would like it to delete one with the shortest length. Is this possible? Nov 19, 2019 at 19:33
  • @ar-siddiqui, please ask it as a new question.
    – Taras
    Mar 24, 2021 at 7:08
3

In QGIS 3, you could use 'Add autoincremental field' tool to distinguish the identical set of attribute fields.

If your ABC field holds A, B, ... and mnp field holds m, p, ... like below image;

enter image description here

Select these ABC, mnp fields in the Group values by option, and keep other options at the default setting.

enter image description here

This tool will return a new Incremental layer. You will see AUTO field with 0 and 1. (You may have 2 or bigger numbers if you have many duplicated records).

enter image description here

Select and highlight AUTO= 0 and go to Save As, using only selected features option.

4
  • How does your answer solve the problem that was to remove the duplicates?
    – user30184
    Nov 10, 2018 at 10:39
  • 1
    @user30184 I think it is the last part (saving only the record with 0), which creates new data without duplicates.
    – Kazuhito
    Nov 10, 2018 at 10:45
  • Ok, I understand now.
    – user30184
    Nov 10, 2018 at 10:47
  • @Kazuhito Great, I'll check it out. Unfortunately, generating the original table is now not working for me - I've identified duplicate geometry in the past with ArcGIS using the "find identical" tool, choosing "shape", but it's not working. I'm trying to do it with QGIS as well. I don't want to delete features with identical geometry, I just want to add a common id for duplicates. Any idea on how to do that? I've posted this question here: gis.stackexchange.com/questions/302215/…
    – nittyjee
    Nov 11, 2018 at 23:41
1

There is a possibility of using a 'Virtual Layer' through Layer > Add Layer > Add/Edit Virtual Layer...

Let's assume there is a point layer 'testpoints' with identical table attributes, see image below.

input

With the following query, it is possible to delete features with identical table attributes.

SELECT "id", "value1", "value2", geometry
FROM "testpoints"
GROUP BY "value1", "value2"

The output layer with its attribute table will look like

result

P.S. Mind that this solution does make sense if features possess the same geometry


References:

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.