Select to view content in your preferred language

Reverse bearing calls in attribute table.

1644
9
Jump to solution
01-04-2013 04:58 AM
NoahHuntington
Deactivated User
Can anybody help with a field calculator expression which reverses the direction of a cogo direction field.  Where N 90 0 0 E becomes S 90 0 0 W?  Any help is greatly appreciated.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
T__WayneWhitley
Honored Contributor
def revBearing(bearStr):  orientation = bearStr[0:1] + bearStr[-1:]  if orientation == 'NE':   testStr = bearStr.replace('N','S')   testStr = testStr.replace('E','W')  elif orientation == 'NW':   testStr = bearStr.replace('N','S')   testStr = testStr.replace('W','E')  elif orientation == 'SE':   testStr = bearStr.replace('S','N')   testStr = testStr.replace('E','W')  elif orientation == 'SW':   testStr = bearStr.replace('S','N')   testStr = testStr.replace('W','E')  else:   # handle something unexpected here   testStr = ''  return testStr


That should do it -- may be a shorter way, but the logic is clear...test this, copy/paste the def statement into the field calculator...follow the example as in the aforemention pic on the webhelp page...to call the function, enter on the code block bottom text box (replacing < your field > with the name of your txt field -- the function has been tested in IDLE, but I didn't go as far to test this in the field calculator, so let me know how it goes):

revBearing(!< your field >!)

View solution in original post

0 Kudos
9 Replies
JonPedder
Deactivated User
Try looking into attribute assistant, it's part of the GIS for local government.
0 Kudos
T__WayneWhitley
Honored Contributor
Interesting problem- you want to reverse all bearings and these values are all contained in one text field, correct?...in addition to the example you gave, you want to reverse, say, N 40 0 0 E  to  S 40 0 0 W  and (one more example) S 60 0 0 E  to  N 60 0 0 W ?

If so, then you only need to change the beginning and ending characters, am I reading you correctly?
(N to S, S to N) for the beginning; (E to W, W to E) for the ending....pardon me, I'm thinking while writing, but the logic would be to change bearings NE to SW, NW to SE, SE to NW, and SW to NE, those 4 cases.  (the actual numeric vals stay the same)

If you have 10.1 you can use the provided python parser to create an exp in the field calculator; otherwise you can still use the VB select case exp in the field calculator.  Or just use a py script (no field calculator) w/ an update cursor.
0 Kudos
NoahHuntington
Deactivated User
Interesting problem- you want to reverse all bearings and these values are all contained in one text field, correct?...in addition to the example you gave, you want to reverse, say, N 40 0 0 E  to  S 40 0 0 W  and (one more example) S 60 0 0 E  to  N 60 0 0 W ?

If so, then you only need to change the beginning and ending characters, am I reading you correctly?


Correct.  Any instance of SE needs to become NW and so on. I could change them individually but was hoping to to automate this process to take care of large records. Thanks for chiming in.
0 Kudos
T__WayneWhitley
Honored Contributor
OK, good, I added to my last post...so which route do you prefer to take?
0 Kudos
NoahHuntington
Deactivated User
I do have 10.1 so python parser would be ideal...
0 Kudos
T__WayneWhitley
Honored Contributor
Ah, good and by the way it also works at 10.0 (I was thinking of labeling), give me a minute will you?....what I'll do is test the a py function using a def statement for the field calculator applied to those 4 cases established above-- something similar to that shown here:


Calculate Field examples  (the section on 'Using Code Blocks', see the 1st pic)
Resource Center » Professional Library » Data Management » Geographic data types » Tables » Calculating field values
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005s0000002m000000
0 Kudos
NoahHuntington
Deactivated User
Take all the time you need.  Thanks for the help!
0 Kudos
T__WayneWhitley
Honored Contributor
def revBearing(bearStr):  orientation = bearStr[0:1] + bearStr[-1:]  if orientation == 'NE':   testStr = bearStr.replace('N','S')   testStr = testStr.replace('E','W')  elif orientation == 'NW':   testStr = bearStr.replace('N','S')   testStr = testStr.replace('W','E')  elif orientation == 'SE':   testStr = bearStr.replace('S','N')   testStr = testStr.replace('E','W')  elif orientation == 'SW':   testStr = bearStr.replace('S','N')   testStr = testStr.replace('W','E')  else:   # handle something unexpected here   testStr = ''  return testStr


That should do it -- may be a shorter way, but the logic is clear...test this, copy/paste the def statement into the field calculator...follow the example as in the aforemention pic on the webhelp page...to call the function, enter on the code block bottom text box (replacing < your field > with the name of your txt field -- the function has been tested in IDLE, but I didn't go as far to test this in the field calculator, so let me know how it goes):

revBearing(!< your field >!)
0 Kudos
NoahHuntington
Deactivated User
Like a charm! Thanks for the help!!!
0 Kudos