the misc/ directory also comes with drupal
[plewww.git] / googlemap / degree2decimal.py
diff --git a/googlemap/degree2decimal.py b/googlemap/degree2decimal.py
new file mode 100755 (executable)
index 0000000..873cd54
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+# transforms a degree notation like
+# 43:36:56.32 (43 degrees 36 minutes 56.32 seconds) 
+# into a decimal notation
+
+import sys
+import re
+pattern="^(-*\d+):(\d+):([\d\.]+)$"
+matcher=re.compile(pattern)
+
+minute=1./60
+second=1./3600
+
+def translate (coord):
+    r=matcher.match(coord)
+    if not r:
+        print 'failed to parse',coord,'pattern=',pattern
+    else:
+        (deg,min,sec)=map(float,r.groups())
+#        print 'deg',deg,'min',min,'sec',sec
+        if (deg>0):
+            print coord,'->',deg+min*minute+sec*second
+        else:
+            print coord,'->',deg-min*minute-sec*second
+            
+
+def main():
+    for arg in sys.argv[1:]:
+        translate(arg)
+    
+if __name__ == '__main__':
+    main()