[Qgis-developer] Finding duplicate records

Eric Goddard egoddard1010 at gmail.com
Sat Mar 1 08:06:13 PST 2014

Python can also be used to find duplicate attributes. It isn't as
straightforward as a sql query, but it works. And if your data isnt in
spatialite/postGIS, I don't know if you can do a select distinct without
creating a more complicated subquery using the expression builder. From the

from collections import Counter

# get a reference to the layer to be searched
layer = iface.activeLayer()

# get the position in the attribute table of the attribute to be checked
idx = layer.fieldNameIndex('attribute_name')

# create a list of all the attribute values
attributeList = [feature.attributes()[idx] for feature in

# print the duplicate entries in the attributeList
print([attribute for attribute, count in Counter(attributeList).items() if
count > 1])


On Fri, Feb 28, 2014 at 8:32 PM, Alex Mandel <tech_dev at wildintellect.com>wrote:

> On 02/28/2014 02:46 AM, Paolo Cavallini wrote:
> > Hi all.
> > I can't recall of any function or plugin to find duplicate data ona
> > table of attributes: am I right, or am I forgetting something?
> > Thanks in advance.
> >
> I always use Spatialite or Postgis so I can run a DISTINCT function in a
> query, or GROUP BY what should be unique and get a count (if it's > 1
> it's not unique). I'm not aware of any other way to check for duplicate
> data.
> Enjoy,
> Alex
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20140301/f06cb9df/attachment.html>

More information about the Qgis-developer mailing list