1

Does anyone know how to create ID numbers for multiple features using python?

For example; (IDs being the object ID, Name and object ID being two different fields)

Names //// IDs

Street 01

River 02

Mountain 03

Hill 04

Names //// Desired IDs;

Street 01

River 01

Mountain 02

River 02

I was hoping to write a code in the Python Parser of the field calculator, as I have over 3 thousand points, every three needing the same ID. I need to have each three consecutive entries given the same numeric ID, in a new field.

  • 1
    Please edit the question to better explain what you mean by "ID". – Vince Nov 27 '15 at 2:49
  • 2
    Can you clarify the algorithm that you are hoping to apply, please? The example you give does not seem to fit "each three consecutive entries given the same numeric ID". What does your expression and code block look like at the moment? – PolyGeo Nov 27 '15 at 22:05
  • Hey PolyGeo, thank your for the reply. I'm not exactly sure where to begin, however I'd like to write one similar to the one I use for creating unique IDs for each row: [link] (gis.stackexchange.com/questions/113691/…) thanks again – John Dec 1 '15 at 23:44
1

I'm assuming that instead of the second "River" value (under desired ID) you mean "Hill".

In the Field Calculator window (for your new field), select the Python parser (in the parser box in the top left of the window), and enter the following into the expression:

{"Street": 01, "River": 01, "Mountain": 02, "Hill":02}[!names!]

What this does is create a dictionary, and specifically return the value for the key as specified by the !names! field. If your field with the text value (street, river, etc) is not called "names" just type in your field name between the exclamation points; ArcMap uses exclamation points in python to identify field name values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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