1

I am trying to create a polygon shapefile layer in QGIS (2.12.1). Because I will be creating many polygons I'm not going to be able to maintain a unique id number manually (without keeping track of it on a piece of paper or something, which is exactly the sort of thing these fancy computers were supposed to replace).

I'm trying to follow these instructions to automatically assign an id after the fact, but every attempt I make to edit the "id" column fails to persist. As soon as I save the edits (or just try sorting the attribute table on the id column or something) everything reverts to NULL.

I see the same behavior in 2.12.0 as well.

Is this supposed to work? Am I missing something obvious?

larsks
  • 1,256
  • 1
  • 11
  • 24
  • for starters, why do you want unique ids? Can you make any edits to any other field? – Maxim Dubinin Dec 01 '15 at 22:03
  • In ArcGIS, the ID field is a phantom, reserved for the row identifier (physical record number and immutable). It's hard to imagine that QGIS didn't take this into account. Name the field anything legal other than "ID" and your procedure might work... – Vince Dec 01 '15 at 23:02
  • I want unique ids so that I have some way to reference the polygons in queries/filters/etc. I suspect that @vince is on to something, because I can create and or edit other fields without a problem...it's just the "id" field that behaves oddly. Maybe this is just a shapefile oddity. – larsks Dec 01 '15 at 23:24
  • 1
    Shapefiles do not have persistent ids. When you open a shapefile the first feature has id=0 and the next ones 1,2,3... If you delete feature id=2 from the middle, after saving and reopening features are reordered and what used to be id=3 is now id=2. You must create your own id "my_id" as a normal attribute and try to deal with it. – user30184 Dec 02 '15 at 07:24
  • @user30184 you should post that as an answer. – larsks Dec 02 '15 at 14:08
  • How you describe it, it should work. This is what I can think of:
    • Did you set the attribute type to a numeric type (no text)?
    • Did you set the layer to editable?
    • Do you have the layer/file open in an other application?
    – Konan Pruiksma Dec 02 '15 at 13:22

0 Answers0