<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: tile code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 04:08:35 GMT</pubDate>
    <description>DZone Snippets: tile code</description>
    <item>
      <title>Converting between 2 google map tile types</title>
      <link>http://snippets.dzone.com/posts/show/531</link>
      <description>Google maps is a marvelous app.&lt;br /&gt;I try to program a prototype of it on pys60&lt;br /&gt;http://bigbold.com/snippets/posts/show/458&lt;br /&gt;&lt;br /&gt;There I only show the default map, not the satellite images.&lt;br /&gt;Retrieving a different mode isn't that difficult.&lt;br /&gt;I read the info from here&lt;br /&gt;http://intepid.com/2005-07-17/21.50/&lt;br /&gt;Then I begin comparing the 2 tile types of the same area&lt;br /&gt;(around California)&lt;br /&gt;http://mt.google.com/mt?v=w2.5&amp;x=20&amp;y=49&amp;zoom=10 (map)&lt;br /&gt;http://kh.google.com/kh?v=3&amp;t=tqtsqrqt (satellite)&lt;br /&gt;&lt;br /&gt;Here's the conversion routine between x,y,zoom and quadtree&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def quadtree(x,y, zoom):&lt;br /&gt;	out = []&lt;br /&gt;	m = {(0,0):'q', (0,1):'t', (1,0):'r', (1,1):'s'}&lt;br /&gt;	for i in range(17-zoom):&lt;br /&gt;		x, rx = divmod(x, 2)&lt;br /&gt;		y, ry = divmod(y, 2)&lt;br /&gt;		out.insert(0, m[(rx,ry)])&lt;br /&gt;	return 't' + ''.join(out)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Then to convert back&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def xyzoom(quad):&lt;br /&gt;	x, y, z = 0, 0, 17&lt;br /&gt;	m = {'q':(0,0), 't':(0,1), 'r':(1,0), 's':(1,1)}&lt;br /&gt; 	for c in quad[1:]:&lt;br /&gt;		x = x*2 + m[c][0]&lt;br /&gt;		y = y*2 + m[c][1]&lt;br /&gt;		z -= 1&lt;br /&gt;	return x, y, z&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Using them is simple&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; quadtree(20,49,10)&lt;br /&gt;'tqtsqrqt'&lt;br /&gt;&gt;&gt;&gt; xyzoom('tqtsqrqt')&lt;br /&gt;(20, 49, 10)&lt;br /&gt;&gt;&gt;&gt; sat_url = 'http://kh.google.com/kh?v=3&amp;t=' + quadtree(20,49,10)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 30 Jul 2005 13:11:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/531</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
