Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
If you need to enforce uniqueness I would recommend using a database e.g. Postgres/PostGIS, Spatailite – Nathan W Jun 20 '12 at 10:26
up vote 4 down vote accepted

If the IDs are consecutive, I would add a new temporary column with unique values like @Ship.shp suggested and then use the query builder to search for ID != uniqueID.

That would return the duplicates directly. After fixing the original IDs, remove the extra column or repeat the whole process as needed — it is not clear what kind of pattern your IDs must match. If they just need to be unique, note the last value first and you can then edit the bad IDs in one iteration, just bumping the number as you go.

share|improve this answer

Use Group Stats plugin and set the ID as a field classification. You can see how many times each value has been entered in 'count' column.

share|improve this answer

A quick (although inelegant) way to do this is to go into Layer properties, select Style - Categorized using the column that you're interested in. Apply this, then right click on the layer in the layers window and check the Show Feature Count checkbox. Then expand the layer in the layers window and you can immediately see how many times each value has been entered.

share|improve this answer

This is a good question onto which I just stumbled myself. I don't like any of the answers which have been given so far. I have a valid dataset with unique IDs that are non sequential and non integer. The problem is that the dataset contains single geometries but some boundaries are multi geometries in nature. My task is to identify and union these geometries.

I recommend to use the DB Manager and SQL for this kind of work. The DB Manager is now part of QGIS. You need to export your data into either PostGIS or a SpatiaLite dataset. SpatiaLite should be the file based data format of choice anyways.

Now you can use count(), group by, and order by as you like and should be able to solve this and other issues rather quickly.

enter image description here

share|improve this answer
Using a SQL plug-in is the best way to go! – Devdatta Tengshe May 19 at 3:25

Yeah I banged my head against the wall for similar problem.

Here is my script for removing features with same ID's. It takes first feature with more than one index attribute and writes it to new feature class.

#Definition of inputs and outputs
# Written by: Gregor Skrt 
##[Example scripts]=group
##unique_field=field input
##output=output vector

#Algorithm body
from qgis.core import *
from PyQt4.QtCore import *
from processing.core.VectorWriter import VectorWriter

# "input" contains the location of the selected layer.
# We get the actual object, so we can get its bounds
layer = processing.getobject(input)
provider = layer.dataProvider()
fields = provider.fields()
writer = VectorWriter(output, None, fields, provider.geometryType(), )

inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
nElement = 0
values = {}

value_field_index = layer.fieldNameIndex(unique_field)

feats = processing.getfeatures(layer)
nFeat = len(feats)

for inFeat in feats:
    progress.setPercentage(int((100 * nElement)/nFeat))
    nElement += 1
    inGeom = inFeat.geometry()
    attrs = inFeat.attributes()
    value = attrs[value_field_index]

    if value not in values:
    #to ne vem ce bo drzalo ???
del writer
share|improve this answer

Also you can use the split by attribute and end up with a seperate table for each value.

I like Rayo's suggestion though. except statist doesn't quite work like I thought it did.
It does give a count of unique values but doesn't help with what those values are.
Another software might add a count field and allow you to export it to csv or other spreadsheet format.

My suggestion for the split layer by attribute is in the vector management tools
management too

split your data on any 1 field an dyou will have your counts.
way more inelegant than ship.ship's solution

share|improve this answer
Please consider upvoting the answers you like! – whuber Jun 20 '12 at 18:58
self upvote is not allowed! – Brad Nesom Nov 20 '12 at 16:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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