Changeset 298

Show
Ignore:
Timestamp:
06/26/07 11:17:45 (1 year ago)
Author:
migurski
Message:

Added new google maps providers, allowing for multi-image hybrid tiles

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/py/compose.py

    r294 r298  
    2424    elif value == 'MICROSOFT_HYBRID': 
    2525        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() 
    2635         
    2736    else: 
     
    6372            return 
    6473 
    65         url = self.provider.getTileUrl(self.coord) 
    66  
     74        urls = self.provider.getTileUrls(self.coord) 
     75         
    6776        if verbose: 
    68             print 'Requesting', url, 'in thread', thread.get_ident() 
     77            print 'Requesting', urls, 'in thread', thread.get_ident() 
    6978 
    7079        # this is the time-consuming part 
    7180        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] 
    7383 
    7484        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                 
    7789        else: 
    78             if lock.acquire()
    79                 if verbose: 
    80                     print 'Received', url, 'in thread', thread.get_ident() 
    81      
    82                 self.img = img 
    83                 self.done = True 
    84                 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() 
    8597 
    8698class RequestQueue(list): 
     
    168180    for job in jobs: 
    169181        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) 
    171184        except: 
    172185            # something failed to paste, so we ignore it 
  • trunk/py/ModestMaps/Google.py

    r206 r298  
    11""" 
    22>>> p = RoadProvider() 
    3 >>> p.getTileUrl(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS 
    4 'http://r....ortho.tiles.virtualearth.net/tiles/r0230102122203031.png?g=45' 
    5 >>> p.getTileUrl(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS 
    6 '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',) 
    77 
    88>>> p = AerialProvider() 
    9 >>> p.getTileUrl(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS 
    10 'http://a....ortho.tiles.virtualearth.net/tiles/a0230102122203031.jpeg?g=45' 
    11 >>> p.getTileUrl(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS 
    12 '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',) 
    1313 
    1414>>> p = HybridProvider() 
    15 >>> p.getTileUrl(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS 
    16 'http://h....ortho.tiles.virtualearth.net/tiles/h0230102122203031.jpeg?g=45' 
    17 >>> p.getTileUrl(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS 
    18 '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') 
    1919""" 
    2020 
     
    2323from Providers import IMapProvider 
    2424 
    25 import random, Tiles 
     25import math, random, Tiles 
     26 
     27ROAD_VERSION = 'w2.52' 
     28AERIAL_VERSION = '18' 
     29HYBRID_VERSION = 'w2t.53' 
    2630 
    2731class AbstractProvider(IMapProvider): 
     
    3337 
    3438    def getZoomString(self, coordinate): 
    35         return Tiles.toMicrosoftRoad(int(coordinate.column), int(coordinate.row), int(coordinate.zoom)
     39        raise NotImplementedError(
    3640 
    3741    def sourceCoordinate(self, coordinate): 
     
    4448 
    4549class 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)) 
    4855 
    4956class 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)) 
    5262 
    5363class 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)) 
    5671 
    5772if __name__ == '__main__': 
  • trunk/py/ModestMaps/Microsoft.py

    r206 r298  
    11""" 
    22>>> p = RoadProvider() 
    3 >>> p.getTileUrl(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS 
    4 'http://r....ortho.tiles.virtualearth.net/tiles/r0230102122203031.png?g=45' 
    5 >>> p.getTileUrl(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS 
    6 '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',) 
    77 
    88>>> p = AerialProvider() 
    9 >>> p.getTileUrl(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS 
    10 'http://a....ortho.tiles.virtualearth.net/tiles/a0230102122203031.jpeg?g=45' 
    11 >>> p.getTileUrl(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS 
    12 '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',) 
    1313 
    1414>>> p = HybridProvider() 
    15 >>> p.getTileUrl(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS 
    16 'http://h....ortho.tiles.virtualearth.net/tiles/h0230102122203031.jpeg?g=45' 
    17 >>> p.getTileUrl(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS 
    18 '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',) 
    1919""" 
    2020 
     
    2323from Providers import IMapProvider 
    2424 
    25 import random, Tiles 
     25import math, random, Tiles 
    2626 
    2727class AbstractProvider(IMapProvider): 
     
    4444 
    4545class 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))),
    4848 
    4949class 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))),
    5252 
    5353class 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))),
    5656 
    5757if __name__ == '__main__': 
  • trunk/py/ModestMaps/Providers.py

    r206 r298  
    1212        raise NotImplementedError("Abstract method not implemented by subclass.") 
    1313         
    14     def getTileUrl(self, coordinate): 
     14    def getTileUrls(self, coordinate): 
    1515        raise NotImplementedError("Abstract method not implemented by subclass.") 
    1616 
  • trunk/py/ModestMaps/__init__.py

    r216 r298  
    66import Geo 
    77import Microsoft 
     8import Google 
    89 
    910TILE_WIDTH = 256