/usr/share/pyshared/ModestMaps/Tiles.py is in python-modestmaps 1.3.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | """
>>> toBinaryString(1)
'1'
>>> toBinaryString(2)
'10'
>>> toBinaryString(3)
'11'
>>> toBinaryString(4)
'100'
>>> fromBinaryString('1')
1
>>> fromBinaryString('11')
3
>>> fromBinaryString('101')
5
>>> fromBinaryString('1001')
9
>>> fromYahooRoad(0, 0, 17)
(0, 0, 1)
>>> fromYahooRoad(10507, 7445, 2)
(10507, 25322, 16)
>>> fromYahooRoad(10482, 7434, 2)
(10482, 25333, 16)
>>> toYahooRoad(0, 0, 1)
(0, 0, 17)
>>> toYahooRoad(10507, 25322, 16)
(10507, 7445, 2)
>>> toYahooRoad(10482, 25333, 16)
(10482, 7434, 2)
>>> fromYahooAerial(0, 0, 17)
(0, 0, 1)
>>> fromYahooAerial(10507, 7445, 2)
(10507, 25322, 16)
>>> fromYahooAerial(10482, 7434, 2)
(10482, 25333, 16)
>>> toYahooAerial(0, 0, 1)
(0, 0, 17)
>>> toYahooAerial(10507, 25322, 16)
(10507, 7445, 2)
>>> toYahooAerial(10482, 25333, 16)
(10482, 7434, 2)
>>> fromMicrosoftRoad('0')
(0, 0, 1)
>>> fromMicrosoftRoad('0230102122203031')
(10507, 25322, 16)
>>> fromMicrosoftRoad('0230102033330212')
(10482, 25333, 16)
>>> toMicrosoftRoad(0, 0, 1)
'0'
>>> toMicrosoftRoad(10507, 25322, 16)
'0230102122203031'
>>> toMicrosoftRoad(10482, 25333, 16)
'0230102033330212'
>>> fromMicrosoftAerial('0')
(0, 0, 1)
>>> fromMicrosoftAerial('0230102122203031')
(10507, 25322, 16)
>>> fromMicrosoftAerial('0230102033330212')
(10482, 25333, 16)
>>> toMicrosoftAerial(0, 0, 1)
'0'
>>> toMicrosoftAerial(10507, 25322, 16)
'0230102122203031'
>>> toMicrosoftAerial(10482, 25333, 16)
'0230102033330212'
"""
import math
octalStrings = ('000', '001', '010', '011', '100', '101', '110', '111')
def toBinaryString(i):
""" Return a binary string for an integer.
"""
return ''.join([octalStrings[int(c)]
for c
in oct(i)]).lstrip('0')
def fromBinaryString(s):
""" Return an integer for a binary string.
"""
s = list(s)
e = 0
i = 0
while(len(s)):
if(s[-1]) == '1':
i += int(math.pow(2, e))
e += 1
s.pop()
return i
def fromYahoo(x, y, z):
""" Return column, row, zoom for Yahoo x, y, z.
"""
zoom = 18 - z
row = int(math.pow(2, zoom - 1) - y - 1)
col = x
return col, row, zoom
def toYahoo(col, row, zoom):
""" Return x, y, z for Yahoo tile column, row, zoom.
"""
x = col
y = int(math.pow(2, zoom - 1) - row - 1)
z = 18 - zoom
return x, y, z
def fromYahooRoad(x, y, z):
""" Return column, row, zoom for Yahoo Road tile x, y, z.
"""
return fromYahoo(x, y, z)
def toYahooRoad(col, row, zoom):
""" Return x, y, z for Yahoo Road tile column, row, zoom.
"""
return toYahoo(col, row, zoom)
def fromYahooAerial(x, y, z):
""" Return column, row, zoom for Yahoo Aerial tile x, y, z.
"""
return fromYahoo(x, y, z)
def toYahooAerial(col, row, zoom):
""" Return x, y, z for Yahoo Aerial tile column, row, zoom.
"""
return toYahoo(col, row, zoom)
microsoftFromCorners = {'0': '00', '1': '01', '2': '10', '3': '11'}
microsoftToCorners = {'00': '0', '01': '1', '10': '2', '11': '3'}
def fromMicrosoft(s):
""" Return column, row, zoom for Microsoft tile string.
"""
row, col = map(fromBinaryString, zip(*[list(microsoftFromCorners[c]) for c in s]))
zoom = len(s)
return col, row, zoom
def toMicrosoft(col, row, zoom):
""" Return string for Microsoft tile column, row, zoom.
"""
x = col
y = row
y, x = toBinaryString(y).rjust(zoom, '0'), toBinaryString(x).rjust(zoom, '0')
string = ''.join([microsoftToCorners[y[c]+x[c]] for c in range(zoom)])
return string
def fromMicrosoftRoad(s):
""" Return column, row, zoom for Microsoft Road tile string.
"""
return fromMicrosoft(s)
def toMicrosoftRoad(col, row, zoom):
""" Return x, y, z for Microsoft Road tile column, row, zoom.
"""
return toMicrosoft(col, row, zoom)
def fromMicrosoftAerial(s):
""" Return column, row, zoom for Microsoft Aerial tile string.
"""
return fromMicrosoft(s)
def toMicrosoftAerial(col, row, zoom):
""" Return x, y, z for Microsoft Aerial tile column, row, zoom.
"""
return toMicrosoft(col, row, zoom)
if __name__ == '__main__':
import doctest
doctest.testmod()
|