Changeset 298
- Timestamp:
- 06/26/07 11:17:45 (1 year ago)
- Files:
-
- trunk/py/compose.py (modified) (3 diffs)
- trunk/py/ModestMaps/Google.py (copied) (copied from trunk/py/ModestMaps/Microsoft.py) (4 diffs)
- trunk/py/ModestMaps/Microsoft.py (modified) (3 diffs)
- trunk/py/ModestMaps/Providers.py (modified) (1 diff)
- trunk/py/ModestMaps/__init__.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/py/compose.py
r294 r298 24 24 elif value == 'MICROSOFT_HYBRID': 25 25 parser.provider = ModestMaps.Microsoft.HybridProvider() 26 27 elif value == 'GOOGLE_ROAD': 28 parser.provider = ModestMaps.Google.RoadProvider() 29 30 elif value == 'GOOGLE_AERIAL': 31 parser.provider = ModestMaps.Google.AerialProvider() 32 33 elif value == 'GOOGLE_HYBRID': 34 parser.provider = ModestMaps.Google.HybridProvider() 26 35 27 36 else: … … 63 72 return 64 73 65 url = self.provider.getTileUrl(self.coord)66 74 urls = self.provider.getTileUrls(self.coord) 75 67 76 if verbose: 68 print 'Requesting', url , 'in thread', thread.get_ident()77 print 'Requesting', urls, 'in thread', thread.get_ident() 69 78 70 79 # this is the time-consuming part 71 80 try: 72 img = PIL.Image.open(StringIO.StringIO(urllib.urlopen(url).read())) 81 imgs = [PIL.Image.open(StringIO.StringIO(urllib.urlopen(url).read())).convert('RGBA') 82 for url in urls] 73 83 74 84 except: 75 print 'Failed', url, 'in thread', thread.get_ident() 76 85 imgs = [None for url in urls] 86 if verbose: 87 print 'Failed', urls, 'in thread', thread.get_ident() 88 77 89 else: 78 if lock.acquire():79 if verbose:80 print 'Received', url, 'in thread', thread.get_ident() 81 82 self.img = img83 self.done = True84 lock.release()90 if verbose: 91 print 'Received', urls, 'in thread', thread.get_ident() 92 93 if lock.acquire(): 94 self.imgs = imgs 95 self.done = True 96 lock.release() 85 97 86 98 class RequestQueue(list): … … 168 180 for job in jobs: 169 181 try: 170 mapImg.paste(job.img, (job.point.x, job.point.y)) 182 for img in job.imgs: 183 mapImg.paste(img, (job.point.x, job.point.y), img) 171 184 except: 172 185 # something failed to paste, so we ignore it trunk/py/ModestMaps/Google.py
r206 r298 1 1 """ 2 2 >>> p = RoadProvider() 3 >>> p.getTileUrl (Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS4 'http://r....ortho.tiles.virtualearth.net/tiles/r0230102122203031.png?g=45' 5 >>> p.getTileUrl (Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS6 'http://r....ortho.tiles.virtualearth.net/tiles/r0230102033330212.png?g=45' 3 >>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS 4 ('http://mt....google.com/mt?n=404&v=...&x=10507&y=25322&zoom=1',) 5 >>> p.getTileUrls(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS 6 ('http://mt....google.com/mt?n=404&v=...&x=10482&y=25333&zoom=1',) 7 7 8 8 >>> p = AerialProvider() 9 >>> p.getTileUrl (Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS10 'http://a....ortho.tiles.virtualearth.net/tiles/a0230102122203031.jpeg?g=45' 11 >>> p.getTileUrl (Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS12 'http://a....ortho.tiles.virtualearth.net/tiles/a0230102033330212.jpeg?g=45' 9 >>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS 10 ('http://kh....google.com/kh?n=404&v=...&t=tqtsqrqtrtttqsqsr',) 11 >>> p.getTileUrls(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS 12 ('http://kh....google.com/kh?n=404&v=...&t=tqtsqrqtqssssqtrt',) 13 13 14 14 >>> p = HybridProvider() 15 >>> p.getTileUrl (Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS16 'http://h....ortho.tiles.virtualearth.net/tiles/h0230102122203031.jpeg?g=45' 17 >>> p.getTileUrl (Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS18 'http://h....ortho.tiles.virtualearth.net/tiles/h0230102033330212.jpeg?g=45' 15 >>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS 16 ('http://kh....google.com/kh?n=404&v=...&t=tqtsqrqtrtttqsqsr', 'http://mt....google.com/mt?n=404&v=...&x=10507&y=25322&zoom=1') 17 >>> p.getTileUrls(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS 18 ('http://kh....google.com/kh?n=404&v=...&t=tqtsqrqtqssssqtrt', 'http://mt....google.com/mt?n=404&v=...&x=10482&y=25333&zoom=1') 19 19 """ 20 20 … … 23 23 from Providers import IMapProvider 24 24 25 import random, Tiles 25 import math, random, Tiles 26 27 ROAD_VERSION = 'w2.52' 28 AERIAL_VERSION = '18' 29 HYBRID_VERSION = 'w2t.53' 26 30 27 31 class AbstractProvider(IMapProvider): … … 33 37 34 38 def getZoomString(self, coordinate): 35 r eturn Tiles.toMicrosoftRoad(int(coordinate.column), int(coordinate.row), int(coordinate.zoom))39 raise NotImplementedError() 36 40 37 41 def sourceCoordinate(self, coordinate): … … 44 48 45 49 class RoadProvider(AbstractProvider): 46 def getTileUrl(self, coordinate): 47 return 'http://r%d.ortho.tiles.virtualearth.net/tiles/r%s.png?g=45' % (random.randint(0, 3), self.getZoomString(coordinate)) 50 def getTileUrls(self, coordinate): 51 return ('http://mt%d.google.com/mt?n=404&v=%s&%s' % (random.randint(0, 3), ROAD_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),) 52 53 def getZoomString(self, coordinate): 54 return 'x=%d&y=%d&zoom=%d' % Tiles.toGoogleRoad(int(coordinate.column), int(coordinate.row), int(coordinate.zoom)) 48 55 49 56 class AerialProvider(AbstractProvider): 50 def getTileUrl(self, coordinate): 51 return 'http://a%d.ortho.tiles.virtualearth.net/tiles/a%s.jpeg?g=45' % (random.randint(0, 3), self.getZoomString(coordinate)) 57 def getTileUrls(self, coordinate): 58 return ('http://kh%d.google.com/kh?n=404&v=%s&t=%s' % (random.randint(0, 3), AERIAL_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),) 59 60 def getZoomString(self, coordinate): 61 return Tiles.toGoogleAerial(int(coordinate.column), int(coordinate.row), int(coordinate.zoom)) 52 62 53 63 class HybridProvider(AbstractProvider): 54 def getTileUrl(self, coordinate): 55 return 'http://h%d.ortho.tiles.virtualearth.net/tiles/h%s.jpeg?g=45' % (random.randint(0, 3), self.getZoomString(coordinate)) 64 def getTileUrls(self, coordinate): 65 under = AerialProvider().getTileUrls(coordinate)[0] 66 over = 'http://mt%d.google.com/mt?n=404&v=%s&%s' % (random.randint(0, 3), HYBRID_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))) 67 return (under, over) 68 69 def getZoomString(self, coordinate): 70 return 'x=%d&y=%d&zoom=%d' % Tiles.toGoogleRoad(int(coordinate.column), int(coordinate.row), int(coordinate.zoom)) 56 71 57 72 if __name__ == '__main__': trunk/py/ModestMaps/Microsoft.py
r206 r298 1 1 """ 2 2 >>> p = RoadProvider() 3 >>> p.getTileUrl (Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS4 'http://r....ortho.tiles.virtualearth.net/tiles/r0230102122203031.png?g=45' 5 >>> p.getTileUrl (Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS6 'http://r....ortho.tiles.virtualearth.net/tiles/r0230102033330212.png?g=45' 3 >>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS 4 ('http://r....ortho.tiles.virtualearth.net/tiles/r0230102122203031.png?g=45',) 5 >>> p.getTileUrls(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS 6 ('http://r....ortho.tiles.virtualearth.net/tiles/r0230102033330212.png?g=45',) 7 7 8 8 >>> p = AerialProvider() 9 >>> p.getTileUrl (Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS10 'http://a....ortho.tiles.virtualearth.net/tiles/a0230102122203031.jpeg?g=45' 11 >>> p.getTileUrl (Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS12 'http://a....ortho.tiles.virtualearth.net/tiles/a0230102033330212.jpeg?g=45' 9 >>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS 10 ('http://a....ortho.tiles.virtualearth.net/tiles/a0230102122203031.jpeg?g=45',) 11 >>> p.getTileUrls(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS 12 ('http://a....ortho.tiles.virtualearth.net/tiles/a0230102033330212.jpeg?g=45',) 13 13 14 14 >>> p = HybridProvider() 15 >>> p.getTileUrl (Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS16 'http://h....ortho.tiles.virtualearth.net/tiles/h0230102122203031.jpeg?g=45' 17 >>> p.getTileUrl (Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS18 'http://h....ortho.tiles.virtualearth.net/tiles/h0230102033330212.jpeg?g=45' 15 >>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS 16 ('http://h....ortho.tiles.virtualearth.net/tiles/h0230102122203031.jpeg?g=45',) 17 >>> p.getTileUrls(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS 18 ('http://h....ortho.tiles.virtualearth.net/tiles/h0230102033330212.jpeg?g=45',) 19 19 """ 20 20 … … 23 23 from Providers import IMapProvider 24 24 25 import random, Tiles25 import math, random, Tiles 26 26 27 27 class AbstractProvider(IMapProvider): … … 44 44 45 45 class RoadProvider(AbstractProvider): 46 def getTileUrl (self, coordinate):47 return 'http://r%d.ortho.tiles.virtualearth.net/tiles/r%s.png?g=45' % (random.randint(0, 3), self.getZoomString(coordinate))46 def getTileUrls(self, coordinate): 47 return ('http://r%d.ortho.tiles.virtualearth.net/tiles/r%s.png?g=45' % (random.randint(0, 3), self.getZoomString(self.sourceCoordinate(coordinate))),) 48 48 49 49 class AerialProvider(AbstractProvider): 50 def getTileUrl (self, coordinate):51 return 'http://a%d.ortho.tiles.virtualearth.net/tiles/a%s.jpeg?g=45' % (random.randint(0, 3), self.getZoomString(coordinate))50 def getTileUrls(self, coordinate): 51 return ('http://a%d.ortho.tiles.virtualearth.net/tiles/a%s.jpeg?g=45' % (random.randint(0, 3), self.getZoomString(self.sourceCoordinate(coordinate))),) 52 52 53 53 class HybridProvider(AbstractProvider): 54 def getTileUrl (self, coordinate):55 return 'http://h%d.ortho.tiles.virtualearth.net/tiles/h%s.jpeg?g=45' % (random.randint(0, 3), self.getZoomString(coordinate))54 def getTileUrls(self, coordinate): 55 return ('http://h%d.ortho.tiles.virtualearth.net/tiles/h%s.jpeg?g=45' % (random.randint(0, 3), self.getZoomString(self.sourceCoordinate(coordinate))),) 56 56 57 57 if __name__ == '__main__': trunk/py/ModestMaps/Providers.py
r206 r298 12 12 raise NotImplementedError("Abstract method not implemented by subclass.") 13 13 14 def getTileUrl (self, coordinate):14 def getTileUrls(self, coordinate): 15 15 raise NotImplementedError("Abstract method not implemented by subclass.") 16 16 trunk/py/ModestMaps/__init__.py
r216 r298 6 6 import Geo 7 7 import Microsoft 8 import Google 8 9 9 10 TILE_WIDTH = 256
