QGIS Attributes – Identifying Duplicate Attributes in Field

attribute-tableduplicationfields-attributesqgisquery

I have a point shapefile with thousands of points. It has an "ID" code field that is supposed to be unique. Every now and then the data entry clerk wrongly type the "ID" creating duplicates. Right now I'm manually scrolling the field to find the duplicate.

Is there another way to do this using the Search Query Builder?

Best Answer

Another graphical, dynamic and most importantly simple way to detect duplicate attributes: use QGIS's expression builder.

Highlight duplicates in attribute table:

Suppose FieldWithDuplicates is the attribute containing duplicates ( TreeID in the screenshot below). Enable Conditional Formatting (see red arrow below) with the following condition:

count(1,"FieldWithDuplicates") > 1

To group all duplicates at the top, right click the column, select Sort
Enter the above expression without the >1, and deselect Sort ascending.

duplicate attributes highlighted in QGIS attribute table

Highlight features with duplicate attributes on canvas:

You could add a new symbol or label with the filter set to the above condition.

And of course you can enable a data derived override based on the the same.

For example, if you want to highlight labels for features with a duplicate attribute, you can set it to draw a label background with the following override:

count(1,"FieldWithDuplicates") > 1

to achieve something like the following

duplicate attribute labels highlighted in QGIS canvas

In both situations, of course, once you either delete or change the duplicate attributes, the formatting/styling updates instantly.

Related Question