I'm trying to avoid manually inputting Begin and End engineering station values already inputted into a seperate field.

I'm dealing with(4) fields:

  • Begin_Sta
  • End_Sta
  • Beg_End and
  • Station.

The Begin_Sta and End_Sta fields have engineering stations. The Beg_End field has either "BEGIN" or "END" inputted. The Station field is the one I want to populate using python in the field calculator.

If Beg_End has "BEGIN" then the engineering station value in the Begin_Sta field is returned into the Station field, else the End_Sta value is used to populate the Station field.

Is this possible using python in the Field Calculator?

  • 4
    With one of your qualifying fields only having two possible values, you can use a definition query to select half of the records and calculate fields as needed. Then, rinse and repeat with another definition query. Or are you wanting to do something else? – Baltok Feb 26 '13 at 15:46
  • As far as getting the job done the query is an excellent idea, and I will use it! However, it would be interesting to learn the language to do this in python. Thanks. – geo_mat Feb 26 '13 at 21:22
  • What format is your data in? What type of GIS software and version is involved? You mention Field Calculator so I am guessing you are using ArcGIS (but what version?). – PolyGeo Feb 27 '13 at 9:14

Yes it is possible, right click your 'Station' field and select Field Calculator. Select python as the parser and check the Show Codeblock box, see screen capture below for code snippet:

enter image description here

  • An easier way to write this (in Python without the code block) is simply: !Begin_Sta! if !Beg_End! == 'BEGIN' else !End_Sta! – Jason Miller Aug 12 '14 at 2:38

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.