Changeset 484

Show
Ignore:
Timestamp:
02/13/08 23:36:28 (7 months ago)
Author:
tom
Message:

implemented Google provider in Processing version

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/processing/modest_maps/Google.pde

    r483 r484  
    11 
    2 /* 
     2void doGoogleTest() { 
    33 
    4 ROAD_VERSION = 'w2.66' 
    5 AERIAL_VERSION = '24' 
    6 HYBRID_VERSION = 'w2t.66' 
    7 TERRAIN_VERSION = 'w2p.64' 
     4  println(); 
     5  println("google test"); 
     6  println(); 
    87 
    9 class AbstractProvider(IMapProvider): 
    10     def __init__(self): 
    11         t = Transformation(1.068070779e7, 0, 3.355443185e7, 
    12                                   0, -1.068070890e7, 3.355443057e7
     8  AbstractMapProvider p = new GoogleRoadProvider(); 
     9  String[] urls = p.getTileUrls(new Coordinate(25322, 10507, 16)); 
     10  println(urls); 
     11  println( urls[0].startsWith("http://mt") && urls[0].endsWith("&x=10507&y=25322&zoom=1") ); //('....google.com/mt?n=404&v=...',
    1312 
    14         self.projection = MercatorProjection(26, t) 
     13  urls = p.getTileUrls(new Coordinate(25333, 10482, 16)); 
     14  println( urls[0].startsWith("http://mt") && urls[0].endsWith("&x=10482&y=25333&zoom=1") ); //('....google.com/mt?n=404&v=...',) 
    1515 
    16     def getZoomString(self, coordinate): 
    17         raise NotImplementedError() 
     16  p = new GoogleAerialProvider(); 
     17  urls = p.getTileUrls(new Coordinate(25322, 10507, 16)); 
     18  println( urls[0].startsWith("http://kh") && urls[0].endsWith("&t=tqtsqrqtrtttqsqsr") ); //google.com/kh?n=404&v= 
    1819 
    19     def tileWidth(self): 
    20         return 256 
     20  urls = p.getTileUrls(new Coordinate(25333, 10482, 16)); 
     21  println( urls[0].startsWith("http://kh") && urls[0].endsWith("&t=tqtsqrqtqssssqtrt") ); //google.com/kh?n=404&v= 
    2122 
    22     def tileHeight(self): 
    23         return 256 
     23  p = new GoogleHybridProvider(); 
     24  urls = p.getTileUrls(new Coordinate(25322, 10507, 16)); 
     25  println(urls); 
     26  println( urls[0].startsWith("http://kh") && urls[0].endsWith("&t=tqtsqrqtrtttqsqsr") ); //google.com/kh?n=404&v= 
     27  println( urls[1].startsWith("http://mt") && urls[1].endsWith("&x=10507&y=25322&zoom=1") ); //google.com/mt?n=404&v= 
    2428 
    25 class RoadProvider(AbstractProvider): 
    26     def getTileUrls(self, coordinate): 
    27         return ('http://mt%d.google.com/mt?n=404&v=%s&%s' % (random.randint(0, 3), ROAD_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),) 
    28          
    29     def getZoomString(self, coordinate): 
    30         return 'x=%d&y=%d&zoom=%d' % Tiles.toGoogleRoad(int(coordinate.column), int(coordinate.row), int(coordinate.zoom)) 
     29  urls = p.getTileUrls(new Coordinate(25333, 10482, 16)); 
     30  println(urls); 
     31  println( urls[0].startsWith("http://kh") && urls[0].endsWith("&t=tqtsqrqtqssssqtrt") ); //google.com/kh?n=404&v= 
     32  println( urls[1].startsWith("http://mt") && urls[1].endsWith("&x=10482&y=25333&zoom=1") ); //google.com/mt?n=404&v= 
     33
    3134 
    32 class AerialProvider(AbstractProvider): 
    33     def getTileUrls(self, coordinate): 
    34         return ('http://kh%d.google.com/kh?n=404&v=%s&t=%s' % (random.randint(0, 3), AERIAL_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),) 
     35abstract class GoogleProvider extends AbstractMapProvider{ 
    3536 
    36     def getZoomString(self, coordinate): 
    37         return Tiles.toGoogleAerial(int(coordinate.column), int(coordinate.row), int(coordinate.zoom)) 
     37  String ROAD_VERSION = "w2.66"; 
     38  String AERIAL_VERSION = "24"; 
     39  String HYBRID_VERSION = "w2t.66"; 
     40  String TERRAIN_VERSION = "w2p.64"; 
    3841 
    39 class HybridProvider(AbstractProvider): 
    40     def getTileUrls(self, coordinate): 
    41         under = AerialProvider().getTileUrls(coordinate)[0] 
    42         over = 'http://mt%d.google.com/mt?n=404&v=%s&%s' % (random.randint(0, 3), HYBRID_VERSION, RoadProvider().getZoomString(self.sourceCoordinate(coordinate))) 
    43         return (under, over) 
     42  GoogleProvider() { 
     43    super( new MercatorProjection(26, new Transformation(1.068070779e7, 0, 3.355443185e7, 0, -1.068070890e7, 3.355443057e7) ) ); 
     44  } 
    4445 
    45 class TerrainProvider(RoadProvider): 
    46     def getTileUrls(self, coordinate): 
    47         return ('http://mt%d.google.com/mt?n=404&v=%s&%s' % (random.randint(0, 3), TERRAIN_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),) 
     46  abstract String getZoomString(Coordinate coordinate); 
    4847 
    49 */ 
     48  int tileWidth() { 
     49    return 256; 
     50  } 
     51 
     52  int tileHeight() { 
     53    return 256; 
     54  } 
     55 
     56
     57 
     58class GoogleRoadProvider extends GoogleProvider { 
     59  String[] getTileUrls(Coordinate coordinate) { 
     60    String url = "http://mt" + (int)random(0, 4) + ".google.com/mt?n=404&v=" + ROAD_VERSION + "&" + getZoomString(sourceCoordinate(coordinate)); 
     61    return new String[] {  
     62      url                     }; 
     63  }    
     64  String getZoomString(Coordinate coordinate) { 
     65    Coordinate coord = toGoogleRoad(coordinate.container()); 
     66    return "x=" + (int)coord.column + "&y=" + (int)coord.row + "&zoom=" + (int)coord.zoom; 
     67  } 
     68
     69 
     70class GoogleAerialProvider extends GoogleProvider { 
     71  String[] getTileUrls(Coordinate coordinate) { 
     72    String url = "http://kh" + (int)random(0, 4) + ".google.com/kh?n=404&v=" + AERIAL_VERSION + "&t=" + getZoomString(sourceCoordinate(coordinate)); 
     73    return new String[] {  
     74      url                 }; 
     75  } 
     76  String getZoomString(Coordinate coordinate) { 
     77    return toGoogleAerial(coordinate.container()); 
     78  } 
     79
     80 
     81class GoogleHybridProvider extends GoogleProvider { 
     82  String[] getTileUrls(Coordinate coordinate) { 
     83    String under = new GoogleAerialProvider().getTileUrls(coordinate)[0]; 
     84    String over = "http://mt" + (int)random(0, 4) + ".google.com/mt?n=404&v=" + HYBRID_VERSION + "&" + getZoomString(sourceCoordinate(coordinate)); 
     85    return new String[] {  
     86      under, over         }; 
     87  } 
     88  String getZoomString(Coordinate coordinate) { 
     89    Coordinate coord = toGoogleRoad(coordinate.container()); 
     90    return "x=" + (int)coord.column + "&y=" + (int)coord.row + "&zoom=" + (int)coord.zoom; 
     91  } 
     92
     93 
     94class GoogleTerrainProvider extends GoogleRoadProvider { 
     95  String[] getTileUrls(Coordinate coordinate) { 
     96    String url = "http://mt" + (int)random(0, 4) + ".google.com/mt?n=404&v=" + TERRAIN_VERSION + "&" + getZoomString(sourceCoordinate(coordinate)); 
     97    return new String[] {  
     98      url     }; 
     99  } 
     100
  • trunk/processing/modest_maps/init.pde

    r483 r484  
    152152    try { 
    153153      for (int i = 0; i < urls.length; i++) { 
    154         imgs[i] = loadImage(urls[i]); 
     154        String type = urls[i].startsWith("http://mt") ? "png" : urls[i].startsWith("http://kh") ? "jpg" : null; 
     155        if (type != null) {  
     156          imgs[i] = loadImage(urls[i], type); 
     157        } 
     158        else { 
     159          imgs[i] = loadImage(urls[i]); 
     160        } 
    155161      } 
    156162    } 
  • trunk/processing/modest_maps/modest_maps.pde

    r483 r484  
    88void draw() { 
    99 
    10   Map m = new Map(new RoadProvider(), new Point(600, 600), new Location(51.5, -0.137), 14); 
     10//  Map m = new Map(new GoogleRoadProvider(), new Point(600, 600), new Coordinate(3165, 1313, 13), new Point(-144, -94)); 
     11  Map m = new Map(new GoogleTerrainProvider(), new Point(600, 600), new Location(51.5, -0.137), 12); 
    1112  PImage img = m.draw(true); 
    1213 
     
    1516  println(img); 
    1617 
    17   image(img,0,0);   
     18  image(img,0,0); 
    1819} 
    1920 
     
    2122  doTilesTest(); 
    2223  doMicrosoftTest(); 
     24  doGoogleTest(); 
    2325  doGeoTest(); 
    2426  doCoreTest(); 
  • trunk/processing/modest_maps/Tiles.pde

    r483 r484  
    44  println("tiles test"); 
    55  println();   
    6    
     6 
    77  println( "1".equals(binary(1)) ); 
    88  println( "10".equals(binary(2)) ); 
     
    1717/* 
    1818>>> fromGoogleRoad(0, 0, 16) 
    19 (0, 0, 1) 
    20 >>> fromGoogleRoad(10507, 25322, 1) 
    21 (10507, 25322, 16) 
    22 >>> fromGoogleRoad(10482, 25333, 1) 
    23 (10482, 25333, 16) 
    24  
    25 >>> toGoogleRoad(0, 0, 1) 
    26 (0, 0, 16) 
    27 >>> toGoogleRoad(10507, 25322, 16) 
    28 (10507, 25322, 1) 
    29 >>> toGoogleRoad(10482, 25333, 16) 
    30 (10482, 25333, 1) 
    31  
    32 >>> fromGoogleAerial('tq') 
    33 (0, 0, 1) 
    34 >>> fromGoogleAerial('tqtsqrqtrtttqsqsr') 
    35 (10507, 25322, 16) 
    36 >>> fromGoogleAerial('tqtsqrqtqssssqtrt') 
    37 (10482, 25333, 16) 
    38  
    39 >>> toGoogleAerial(0, 0, 1) 
    40 'tq' 
    41 >>> toGoogleAerial(10507, 25322, 16) 
    42 'tqtsqrqtrtttqsqsr' 
    43 >>> toGoogleAerial(10482, 25333, 16) 
    44 'tqtsqrqtqssssqtrt' 
    45  
    46 >>> fromYahooRoad(0, 0, 17) 
    47 (0, 0, 1) 
    48 >>> fromYahooRoad(10507, 7445, 2) 
    49 (10507, 25322, 16) 
    50 >>> fromYahooRoad(10482, 7434, 2) 
    51 (10482, 25333, 16) 
    52  
    53 >>> toYahooRoad(0, 0, 1) 
    54 (0, 0, 17) 
    55 >>> toYahooRoad(10507, 25322, 16) 
    56 (10507, 7445, 2) 
    57 >>> toYahooRoad(10482, 25333, 16) 
    58 (10482, 7434, 2) 
    59  
    60 >>> fromYahooAerial(0, 0, 17) 
    61 (0, 0, 1) 
    62 >>> fromYahooAerial(10507, 7445, 2) 
    63 (10507, 25322, 16) 
    64 >>> fromYahooAerial(10482, 7434, 2) 
    65 (10482, 25333, 16) 
    66  
    67 >>> toYahooAerial(0, 0, 1) 
    68 (0, 0, 17) 
    69 >>> toYahooAerial(10507, 25322, 16) 
    70 (10507, 7445, 2) 
    71 >>> toYahooAerial(10482, 25333, 16) 
    72 (10482, 7434, 2) 
    73  
     19   (0, 0, 1) 
     20   >>> fromGoogleRoad(10507, 25322, 1) 
     21   (10507, 25322, 16) 
     22   >>> fromGoogleRoad(10482, 25333, 1) 
     23   (10482, 25333, 16) 
     24    
     25   >>> toGoogleRoad(0, 0, 1) 
     26   (0, 0, 16) 
     27   >>> toGoogleRoad(10507, 25322, 16) 
     28   (10507, 25322, 1) 
     29   >>> toGoogleRoad(10482, 25333, 16) 
     30   (10482, 25333, 1) 
     31    
     32   >>> fromGoogleAerial('tq') 
     33   (0, 0, 1) 
     34   >>> fromGoogleAerial('tqtsqrqtrtttqsqsr') 
     35   (10507, 25322, 16) 
     36   >>> fromGoogleAerial('tqtsqrqtqssssqtrt') 
     37   (10482, 25333, 16) 
     38    
     39   >>> toGoogleAerial(0, 0, 1) 
     40   'tq' 
     41   >>> toGoogleAerial(10507, 25322, 16) 
     42   'tqtsqrqtrtttqsqsr' 
     43   >>> toGoogleAerial(10482, 25333, 16) 
     44   'tqtsqrqtqssssqtrt' 
    7445*/ 
     46/*    
     47   >>> fromYahooRoad(0, 0, 17) 
     48   (0, 0, 1) 
     49   >>> fromYahooRoad(10507, 7445, 2) 
     50   (10507, 25322, 16) 
     51   >>> fromYahooRoad(10482, 7434, 2) 
     52   (10482, 25333, 16) 
     53    
     54   >>> toYahooRoad(0, 0, 1) 
     55   (0, 0, 17) 
     56   >>> toYahooRoad(10507, 25322, 16) 
     57   (10507, 7445, 2) 
     58   >>> toYahooRoad(10482, 25333, 16) 
     59   (10482, 7434, 2) 
     60    
     61   >>> fromYahooAerial(0, 0, 17) 
     62   (0, 0, 1) 
     63   >>> fromYahooAerial(10507, 7445, 2) 
     64   (10507, 25322, 16) 
     65   >>> fromYahooAerial(10482, 7434, 2) 
     66   (10482, 25333, 16) 
     67    
     68   >>> toYahooAerial(0, 0, 1) 
     69   (0, 0, 17) 
     70   >>> toYahooAerial(10507, 25322, 16) 
     71   (10507, 7445, 2) 
     72   >>> toYahooAerial(10482, 25333, 16) 
     73   (10482, 7434, 2) 
     74    
     75   */ 
    7576 
    7677  Coordinate c = fromMicrosoftRoad("0"); 
     
    9192  e = fromMicrosoftAerial("0230102033330212"); 
    9293  println(e.column == 25333.0 && e.row == 10482.0 && e.zoom == 16.0); 
    93   
     94 
    9495  println( "0".equals( toMicrosoftAerial(0, 0, 1) ) ); 
    9596  println( "0230102122203031".equals(toMicrosoftAerial(10507, 25322, 16) ) ); 
     
    9899} 
    99100 
    100  
    101  
    102 /* 
    103 String[] octalStrings = { "000", "001", "010", "011", "100", "101", "110", "111" }; 
    104  
    105 def fromGoogleRoad(x, y, z) { 
    106     """ Return column, row, zoom for Google Road tile x, y, z. 
    107     """ 
    108     col = x 
    109     row = y 
    110     zoom = 17 - z 
    111     return col, row, zoom 
    112  
    113 def toGoogleRoad(col, row, zoom) { 
    114     """ Return x, y, z for Google Road tile column, row, zoom. 
    115     """ 
    116     x = col 
    117     y = row 
    118     z = 17 - zoom 
    119     return col, row, z 
    120  
    121 googleFromCorners = {'t' { '00', 's' { '01', 'q' { '10', 'r' { '11'} 
    122 googleToCorners = {'00' { 't', '01' { 's', '10' { 'q', '11' { 'r'} 
    123  
    124 def fromGoogleAerial(s) { 
    125     """ Return column, row, zoom for Google Aerial tile string. 
    126     """ 
    127     row, col = map(fromBinaryString, zip(*[list(googleFromCorners[c]) for c in s])) 
    128     zoom = len(s) - 1 
    129     row = int(math.pow(2, zoom) - row - 1) 
    130     return col, row, zoom 
    131  
    132 def toGoogleAerial(col, row, zoom) { 
    133     """ Return string for Google Road tile column, row, zoom. 
    134     """ 
    135     x = col 
    136     y = int(math.pow(2, zoom) - row - 1) 
    137     z = zoom + 1 
    138     y, x = toBinaryString(y).rjust(z, '0'), toBinaryString(x).rjust(z, '0') 
    139     string = ''.join([googleToCorners[y[c]+x[c]] for c in range(z)]) 
    140     return string 
    141 */ 
     101Coordinate fromGoogleRoad(Coordinate coord) { 
     102  // Return column, row, zoom for Google Road tile x, y, z. 
     103  return new Coordinate(coord.row, coord.column, 17 - coord.zoom); 
     104
     105 
     106Coordinate toGoogleRoad(Coordinate coord) { 
     107  // Return x, y, z for Google Road tile column, row, zoom. 
     108  return new Coordinate(coord.row, coord.column, 17 - coord.zoom); 
     109
     110 
     111 
     112//googleFromCorners = {'t' { '00', 's' { '01', 'q' { '10', 'r' { '11'} 
     113//googleToCorners = {'00' { 't', '01' { 's', '10' { 'q', '11' { 'r'} 
     114 
     115Coordinate fromGoogleAerial(String s) { 
     116  // Return column, row, zoom for Google Aerial tile string. 
     117  String rowS = ""; 
     118  String colS = ""; 
     119  for (int i = 0; i < s.length(); i++) { 
     120    switch (s.charAt(i)) { 
     121    case 't': 
     122      rowS += '0'; 
     123      colS += '0'; 
     124      break; 
     125    case 's': 
     126      rowS += '0'; 
     127      colS += '1'; 
     128      break; 
     129    case 'q': 
     130      rowS += '1'; 
     131      colS += '0'; 
     132      break; 
     133    case 'r': 
     134      rowS += '1'; 
     135      colS += '1'; 
     136      break; 
     137    } 
     138  } 
     139  int row = unbinary(rowS); 
     140  int col = unbinary(colS); 
     141  int zoom = s.length() - 1; 
     142  row = (int)pow(2, zoom) - row - 1; 
     143  return new Coordinate( row, col, zoom ); 
     144
     145 
     146String toGoogleAerial(Coordinate coord) { 
     147  // Return string for Google Road tile column, row, zoom. 
     148  int x = (int)coord.column; 
     149  int y = (int)pow(2, coord.zoom) - (int)coord.row - 1; 
     150  int z = (int)coord.zoom + 1; 
     151  String yb = binary(y,z); 
     152  String xb = binary(x,z); 
     153  String string = ""; 
     154  String googleToCorners = "tsqr"; 
     155  for (int c = 0; c < z; c++) { 
     156    string += googleToCorners.charAt(unbinary("" + yb.charAt(c) + xb.charAt(c))); 
     157  } 
     158  return string; 
     159
    142160 
    143161/* 
    144162def fromYahoo(x, y, z) { 
    145     """ Return column, row, zoom for Yahoo x, y, z. 
    146     """ 
    147     zoom = 18 - z 
    148     row = int(math.pow(2, zoom - 1) - y - 1) 
    149     col = x 
    150     return col, row, zoom 
    151  
    152 def toYahoo(col, row, zoom) { 
    153     """ Return x, y, z for Yahoo tile column, row, zoom. 
    154     """ 
    155     x = col 
    156     y = int(math.pow(2, zoom - 1) - row - 1) 
    157     z = 18 - zoom 
    158     return x, y, z 
    159  
    160 def fromYahooRoad(x, y, z) { 
    161     """ Return column, row, zoom for Yahoo Road tile x, y, z. 
    162     """ 
    163     return fromYahoo(x, y, z) 
    164  
    165 def toYahooRoad(col, row, zoom) { 
    166     """ Return x, y, z for Yahoo Road tile column, row, zoom. 
    167     """ 
    168     return toYahoo(col, row, zoom) 
    169  
    170 def fromYahooAerial(x, y, z) { 
    171     """ Return column, row, zoom for Yahoo Aerial tile x, y, z. 
    172     """ 
    173     return fromYahoo(x, y, z) 
    174  
    175 def toYahooAerial(col, row, zoom) { 
    176     """ Return x, y, z for Yahoo Aerial tile column, row, zoom. 
    177     """ 
    178     return toYahoo(col, row, zoom) 
    179  
    180 */ 
     163 """ Return column, row, zoom for Yahoo x, y, z. 
     164 """ 
     165 zoom = 18 - z 
     166 row = int(math.pow(2, zoom - 1) - y - 1) 
     167 col = x 
     168 return col, row, zoom 
     169  
     170 def toYahoo(col, row, zoom) { 
     171 """ Return x, y, z for Yahoo tile column, row, zoom. 
     172 """ 
     173 x = col 
     174 y = int(math.pow(2, zoom - 1) - row - 1) 
     175 z = 18 - zoom 
     176 return x, y, z 
     177  
     178 def fromYahooRoad(x, y, z) { 
     179 """ Return column, row, zoom for Yahoo Road tile x, y, z. 
     180 """ 
     181 return fromYahoo(x, y, z) 
     182  
     183 def toYahooRoad(col, row, zoom) { 
     184 """ Return x, y, z for Yahoo Road tile column, row, zoom. 
     185 """ 
     186 return toYahoo(col, row, zoom) 
     187  
     188 def fromYahooAerial(x, y, z) { 
     189 """ Return column, row, zoom for Yahoo Aerial tile x, y, z. 
     190 """ 
     191 return fromYahoo(x, y, z) 
     192  
     193 def toYahooAerial(col, row, zoom) { 
     194 """ Return x, y, z for Yahoo Aerial tile column, row, zoom. 
     195 """ 
     196 return toYahoo(col, row, zoom) 
     197  
     198 */ 
    181199 
    182200