X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap.git;a=blobdiff_plain;f=userdir_ldap.py;h=21b215bd7c24f0634b495cbeb00b0de6a0cdcb3a;hp=eab3cabbf2a6c2c41cf6378a4af921737b6bc8bd;hb=51f98437460dd3adac2cacd9510551dd2f3d54a7;hpb=8ea8b0937fb83d1db795b20b96acccff2ab4025a diff --git a/userdir_ldap.py b/userdir_ldap.py index eab3cab..21b215b 100644 --- a/userdir_ldap.py +++ b/userdir_ldap.py @@ -168,3 +168,33 @@ def FlushOutstanding(l,Outstanding,Fast=0): if Fast == 0: print; return Outstanding; + +# Convert a lat/long attribute into Decimal degrees +def DecDegree(Attr,Type,Anon=0): + Parts = re.match('[+-]?(\d*)\\.?(\d*)?',GetAttr(Attr,Type)).groups(); + Val = string.atof(GetAttr(Attr,Type)); + + if (abs(Val) >= 1806060.0): + raise ValueError,"Too Big"; + + # Val is in DGMS + if abs(Val) >= 18060.0 or len(Parts[0]) > 5: + Val = Val/100.0; + Secs = Val - long(Val); + Val = long(Val)/100.0; + Min = Val - long(Val); + Val = long(Val) + (Min*100.0 + Secs*100.0/60.0)/60.0; + + # Val is in DGM + elif abs(Val) >= 180 or len(Parts[0]) > 3: + Val = Val/100.0; + Min = Val - long(Val); + Val = long(Val) + Min*100.0/60.0; + + if Anon != 0: + Str = "%3.2f"%(Val); + else: + Str = str(Val); + if Val >= 0: + return "+" + Str; + return Str;