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.
-
1Please edit the question to better explain what you mean by "ID".Vince– Vince2015年11月27日 02:49:09 +00:00Commented Nov 27, 2015 at 2:49
-
2Can 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– PolyGeo ♦2015年11月27日 22:05:08 +00:00Commented Nov 27, 2015 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 againJohn– John2015年12月01日 23:44:22 +00:00Commented Dec 1, 2015 at 23:44
1 Answer 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.
Explore related questions
See similar questions with these tags.