tags:

views:

58

answers:

2

What is the standard way to enter degrees into python? My total station gives degrees in degree-minute-second format. I could write a function to convert this to a decimal degree but I would like to know if there is a common way to do this that I am unaware of.

-Chris

+1  A: 

Python uses radians, as a float.

There is no specific "angle" type, although you can write one yourself as needed.

Ignacio Vazquez-Abrams
That's what I figured. Thank you for the quick reply.
dustynachos
+2  A: 

Chris: not likely.

Since you need radians, anyway, this should od the trick:

import math
def radians_from_triple(deg, min=0, sec=0):
    return math.radians(deg + min * 60 ** -1 + sec * 60 ** -2)
jsbueno
Any particular reason for not using `return math.radians(deg + min / 60.0 + sec / 3600.0)` ??
John Machin
Because the double asterix looks cooler...
dustynachos
@user266564: Double Asterix is Obelix; he's not cool. Looks to me like Obfuscationtrix.
John Machin
@John: I could argue that putting "3600" in the code is obfuscation instead. What is being performed here is a base-conversion from base 60. It could only be considered obfuscation if the reader would not know the ** is the power operator in Python.
jsbueno
@jsbueno: So `sec / 3600.0` is obfuscation and `sec * 60 ** -2` is not? Surely you jest! 3600 could only be considered obfuscation if the reader would not know that 60 * 60 == 3600. What's your justification for `min * 60 ** -1` instead of `min / 60.0`?
John Machin