source: subversion/applications/routing/pyroute/util_binary.py @ 20924

Last change on this file since 20924 was 6020, checked in by ojw, 12 years ago

Move some binary encoding stuff into library

File size: 512 bytes
RevLine 
[6020]1from struct import *
2
3def encodeLL(lat,lon):
4  pLat = (lat + 90.0) / 180.0 
5  pLon = (lon + 180.0) / 360.0 
6  iLat = encodeP(pLat)
7  iLon = encodeP(pLon)
8  return(pack("II", iLat, iLon))
9 
10def encodeP(p):
11  i = int(p * 4294967296.0)
12  return(i)
13 
14
15def decodeLL(data):
16  iLat,iLon = unpack("II", data)
17  pLat = decodeP(iLat)
18  pLon = decodeP(iLon)
19  lat = pLat * 180.0 - 90.0
20  lon = pLon * 360.0 - 180.0
21  return(lat,lon)
22 
23def decodeP(i):
24  p = float(i) / 4294967296.0
25  return(p)
26 
Note: See TracBrowser for help on using the repository browser.