Solved! Go to Solution.
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
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?
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