gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15945
  • QQ554730525
  • 铜币25337枚
  • 威望15352点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
阅读:3880回复:0

[转帖]Google地图数据算法

楼主#
更多 发布于:2011-09-14 10:06
昨天用Google地图的API给一个项目做了个地图。然后顺带着研究了一下google的图片存取算法,感觉不是很难。<br/>好下面我们来看看,我们学校的图。<br/>Google Maps与Google Earth中的每个级别的每一副图片都有一个URL,例如下面这幅我们学校的图的地址是<font face="Arial"><a href="http://kh.google.com/kh?v=3;t=trstrqqrsstttqtss">http://kh.google.com/kh?v=3;t=trstrqqrsstttqtss</a> (这个就是图的URL)</font><br/><a class="fitimg" href="http://kh.google.com/kh?v=3;t=trstrqqrsstttqtss"><img alt="" src="http://kh.google.com/kh?v=3;t=trstrqqrsstttqtss"/></a>       <a class="fitimg" href="http://intepid.com/res/459.gif" target="_blank"><img alt="" src="http://intepid.com/res/459.gif"/></a><br/>URL中的变量v=3代表,卫星图的投影算法采用<a href="http://en.wikipedia.org/wiki/Mercator_projection">Mercator projection</a>算法,v=2代表另外一种算法(已不再支持)<p><strong>变量t=trstrqqrsstttqtss</strong>,这个就是这张图片的编码了,trstrqqrsstttqtss是由一种类似“Q树”的算法计算的。他将一幅图片的左上、右上、左下、右下用<strong>q,r,t,s</strong>分别表示。然后依次递归下去。最上层的是<strong>t</strong>。</p><p><font face="Arial">如果我想看最顶级别的世界地图那么编码就是“t”,URL如下:<br/><a href="http://kh.google.com/kh?v=3;t=t">http://kh.google.com/kh?v=3;t=t</a>  点击左边的链接你将看到世界地图(最大的级别)。</font></p><p>如果我继续找到中国所在的图(实际上就是上图中的右上角部分),那么编码是“tr”,URL如下:<font face="Arial"><br/><font face="Arial"><a href="http://kh.google.com/kh?v=3;t=tr">http://kh.google.com/kh?v=3;t=tr</a> 点击左边的链接你将看到上幅世界地图的右上角部分(也就是包含中国的部分)。<br/>依次类推你就能找到你需要找的位置的地图了。(下图是对这个操纵的一个简单解释,右上角用黄色框表示“r”)<br/><a class="fitimg" href="http://pdjh01.mofile.com/p/1/2007/8/5/NL/NL2H0XVWXL_104_180_160.jpg" target="_blank"><img alt="" src="http://pdjh01.mofile.com/p/1/2007/8/5/NL/NL2H0XVWXL_104_180_160.jpg"/></a><br/>下面是一个工具,在这个工具中输入你的经纬度,他将自动递归每一幅图像。你可以一步步看看google maps是怎么找到你的位置的。<font face="Arial"><a href="http://intepid.com/stuff/gmkh/">http://intepid.com/stuff/gmkh/</a></font></font></font></p><p><font face="Arial"><font face="Arial">关于Q-tress可以找本数据结构的书学习一下,下面是我从维基百科中找到的图 <br/><a class="fitimg" href="http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Point_quadtree.svg/300px-Point_quadtree.svg.png" target="_blank"><img alt="" src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Point_quadtree.svg/300px-Point_quadtree.svg.png"/></a></font></font></p><p><font face="Arial"><font face="Arial">下面是javascript对于此算法的程序(包含编码以及经纬度)</font></font></p><font face="Arial"><font face="Arial"><div style="'color:" rgb(0, 0, 0); line-height: 1.18; font-family: "Courier New",monospace; font-size: 12px; background-color: rgb(255, 255, 255);'><div><span style="color: rgb(0, 0, 255);">function </span><span style="color: rgb(128, 128, 0); font-weight: bold;">GetQuadtreeAddress</span><span style="color: rgb(255, 0, 0);">(</span>long, lat<span style="color: rgb(255, 0, 0);">)</span></div><div><span style="color: rgb(255, 0, 0);">{</span></div><div style="margin-left: 1.5em;"><span style="color: rgb(0, 0, 255);"></span><span style="color: rgb(0, 0, 255);">var </span><font color="#000000">PI = </font><span style="color: rgb(68, 68, 68); font-weight: bold;">3.1415926535897</span><span style="color: rgb(255, 0, 0);">;</span></div><div style="margin-left: 1.5em;"><span style="color: rgb(0, 0, 255);">var </span>digits = <span style="color: rgb(68, 68, 68); font-weight: bold;">18</span><span style="color: rgb(255, 0, 0);">;</span> <span style="color: rgb(127, 161, 161); font-style: italic;">// how many digits precision</span></div><div style="margin-left: 1.5em;"></div><div style="margin-left: 3em;"><span style="color: rgb(127, 161, 161); font-style: italic;">// now convert to normalized square coordinates</span></div><div style="margin-left: 3em;"><span style="color: rgb(127, 161, 161); font-style: italic;">// use standard equations to map into mercator projection</span></div><div style="margin-left: 1.5em;"><span style="color: rgb(0, 0, 255);">var </span>x = <span style="color: rgb(255, 0, 0);">(</span><span style="color: rgb(68, 68, 68); font-weight: bold;">180.0 </span>+ <span style="color: rgb(128, 128, 0); font-weight: bold;">parseFloat</span><span style="color: rgb(255, 0, 0);">(</span>long<span style="color: rgb(255, 0, 0);">)) </span>/ <span style="color: rgb(68, 68, 68); font-weight: bold;">360.0</span><span style="color: rgb(255, 0, 0);">;</span></div><div style="margin-left: 1.5em;"><span style="color: rgb(0, 0, 255);">var </span>y = -<span style="color: rgb(128, 128, 0); font-weight: bold;">parseFloat</span><span style="color: rgb(255, 0, 0);">(</span>lat<span style="color: rgb(255, 0, 0);">) </span>* PI / <span style="color: rgb(68, 68, 68); font-weight: bold;">180</span><span style="color: rgb(255, 0, 0);">;</span> <span style="color: rgb(127, 161, 161); font-style: italic;">// convert to radians</span></div><div style="margin-left: 1.5em;">y = <span style="color: rgb(68, 68, 68); font-weight: bold;">0.5 </span>* <span style="color: rgb(0, 68, 68); font-weight: bold;">Math.</span><span style="color: rgb(128, 128, 0); font-weight: bold;">log</span><span style="color: rgb(255, 0, 0);">((</span><span style="color: rgb(68, 68, 68); font-weight: bold;">1</span>+<span style="color: rgb(0, 68, 68); font-weight: bold;">Math.</span><span style="color: rgb(128, 128, 0); font-weight: bold;">sin</span><span style="color: rgb(255, 0, 0);">(</span>y<span style="color: rgb(255, 0, 0);">)) </span>/ <span style="color: rgb(255, 0, 0);">(</span><span style="color: rgb(68, 68, 68); font-weight: bold;">1 </span>- <span style="color: rgb(0, 68, 68); font-weight: bold;">Math.</span><span style="color: rgb(128, 128, 0); font-weight: bold;">sin</span><span style="color: rgb(255, 0, 0);">(</span>y<span style="color: rgb(255, 0, 0);">)));</span></div><div style="margin-left: 1.5em;"></div><div style="margin-left: 1.5em;">y *= <span style="color: rgb(68, 68, 68); font-weight: bold;">1.0</span>/<span style="color: rgb(255, 0, 0);">(</span><span style="color: rgb(68, 68, 68); font-weight: bold;">2 </span>* PI<span style="color: rgb(255, 0, 0);">);</span> <span style="color: rgb(127, 161, 161); font-style: italic;">// scale factor from radians to normalized </span></div><div style="margin-left: 1.5em;"></div><div style="margin-left: 1.5em;">y += <span style="color: rgb(68, 68, 68); font-weight: bold;">0.5</span><span style="color: rgb(255, 0, 0);">;</span> <span style="color: rgb(127, 161, 161); font-style: italic;">// and make y range from 0 - 1</span></div><div style="margin-left: 1.5em;"></div><div style="margin-left: 1.5em;"><span style="color: rgb(0, 0, 255);">var </span>quad = <span style="color: rgb(127, 127, 255);">"t"</span><span style="color: rgb(255, 0, 0);">;</span> <span style="color: rgb(127, 161, 161); font-style: italic;">// google addresses start with t</span></div><div style="margin-left: 1.5em;"><span style="color: rgb(0, 0, 255);">var </span>lookup = <span style="color: rgb(127, 127, 255);">"qrts"</span><span style="color: rgb(255, 0, 0);">;</span> <span style="color: rgb(127, 161, 161); font-style: italic;">// tl tr bl br</span></div><div style="margin-left: 1.5em;"></div><div style="margin-left: 1.5em;"><span style="color: rgb(0, 0, 255);">while </span><span style="color: rgb(255, 0, 0);">(</span>digits–<span style="color: rgb(255, 0, 0);">) </span><span style="color: rgb(127, 161, 161); font-style: italic;">// (post-decrement)</span></div><div style="margin-left: 1.5em;"><span style="color: rgb(255, 0, 0);">{</span></div><div style="margin-left: 4.5em;"><span style="color: rgb(127, 161, 161); font-style: italic;">// make sure we only look at fractional part</span></div><div style="margin-left: 3em;">x -= <span style="color: rgb(0, 68, 68); font-weight: bold;">Math.</span><span style="color: rgb(128, 128, 0); font-weight: bold;">floor</span><span style="color: rgb(255, 0, 0);">(</span>x<span style="color: rgb(255, 0, 0);">);</span></div><div style="margin-left: 3em;">y -= <span style="color: rgb(0, 68, 68); font-weight: bold;">Math.</span><span style="color: rgb(128, 128, 0); font-weight: bold;">floor</span><span style="color: rgb(255, 0, 0);">(</span>y<span style="color: rgb(255, 0, 0);">);</span></div><div style="margin-left: 3em;"></div><div style="margin-left: 3em;">quad = quad + <span style="color: rgb(0, 68, 68); font-weight: bold;">lookup.</span><span style="color: rgb(128, 128, 0); font-weight: bold;">substr</span><span style="color: rgb(255, 0, 0);">((</span>x >= <span style="color: rgb(68, 68, 68); font-weight: bold;">0.5 </span>? <span style="color: rgb(68, 68, 68); font-weight: bold;">1 </span>: <span style="color: rgb(68, 68, 68); font-weight: bold;">0</span><span style="color: rgb(255, 0, 0);">) </span>+ <span style="color: rgb(255, 0, 0);">(</span>y >= <span style="color: rgb(68, 68, 68); font-weight: bold;">0.5 </span>? <span style="color: rgb(68, 68, 68); font-weight: bold;">2 </span>: <span style="color: rgb(68, 68, 68); font-weight: bold;">0</span><span style="color: rgb(255, 0, 0);">)</span>, <span style="color: rgb(68, 68, 68); font-weight: bold;">1</span><span style="color: rgb(255, 0, 0);">);</span></div><div style="margin-left: 3em;"></div><div style="margin-left: 4.5em;"><span style="color: rgb(127, 161, 161); font-style: italic;">// now descend into that square</span></div><div style="margin-left: 3em;">x *= <span style="color: rgb(68, 68, 68); font-weight: bold;">2</span><span style="color: rgb(255, 0, 0);">;</span></div><div style="margin-left: 3em;">y *= <span style="color: rgb(68, 68, 68); font-weight: bold;">2</span><span style="color: rgb(255, 0, 0);">;</span></div><div style="margin-left: 1.5em;"><span style="color: rgb(255, 0, 0);">}</span></div><div style="margin-left: 1.5em;"><span style="color: rgb(0, 0, 255);">return </span>quad<span style="color: rgb(255, 0, 0);">;</span></div><div><span style="color: rgb(255, 0, 0);">}</span></div></div><p>以上内容参考:<br/><font face="Arial"><a href="http://intepid.com/2005-07-17/21.50/">http://intepid.com/2005-07-17/21.50/</a> </font></p></font></font>
喜欢0 评分0
游客

返回顶部