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

Is there a way to create an auto increment primary key column when creating a new Shapefile in QGIS?

share|improve this question
up vote 4 down vote accepted

As far as I know, Shapefiles have no concept of primary key or auto increment data types.

What you can do is use Field Calculator to populate a column with row number.

share|improve this answer
The only issue is that they seem to change when I edit the data and recalculate; I think the best option is to switch to Spatialite. – mattwigway Oct 16 '11 at 23:17

I get this question a lot on the pyshp mailing list and underdark is correct. The shapefile format provides no unique identifiers for geometry or attribute records.

The object id, feature id, or other GUID is a trapping of the software you use and is just a row number assigned as the records are read in. The only options are to assign a new attribute using scripting or spreadsheet software, or load the data into a spatial database.

share|improve this answer

A Shapefile has a OBJECTID field; which serves as its key and primary index which should suit your purposes.

share|improve this answer
I believe this is the same as the row number, and is what ArcGIS uses, but I'm not sure. – mattwigway Oct 16 '11 at 23:16
But the OBJECTID can change as you delete rows; but that is the primary index. – D.E.Wright Oct 17 '11 at 15:12

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.