source: subversion/applications/routing/pyroute-dev/util_binary.py

Last change on this file was 18455, checked in by buerste, 10 years ago

-remove BOM
-fix version strings

  • Property svn:keywords set to Rev
File size: 1.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5"""
6
7__version__ = "$Rev: 18455 $"[1:-2]
8__license__ = """This program is free software: you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation, either version 3 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program. If not, see <http://www.gnu.org/licenses/>."""
20_debug = 0
21
22
23from struct import *
24
25def encodeLL(lat,lon):
26        pLat = (lat + 90.0) / 180.0
27        pLon = (lon + 180.0) / 360.0
28        iLat = encodeP(pLat)
29        iLon = encodeP(pLon)
30        return(pack("II", iLat, iLon))
31
32def encodeP(p):
33        i = int(p * 4294967296.0)
34        return(i)
35
36
37def decodeLL(data):
38        iLat,iLon = unpack("II", data)
39        pLat = decodeP(iLat)
40        pLon = decodeP(iLon)
41        lat = pLat * 180.0 - 90.0
42        lon = pLon * 360.0 - 180.0
43        return(lat,lon)
44
45def decodeP(i):
46        p = float(i) / 4294967296.0
47        return(p)
Note: See TracBrowser for help on using the repository browser.