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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 27, 2015 at 1:02
3
  • 1
    Please edit the question to better explain what you mean by "ID". Commented Nov 27, 2015 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? Commented 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 again Commented Dec 1, 2015 at 23:44

1 Answer 1

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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Apr 15, 2016 at 16:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.