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

[转帖]GoogleEarth二次开发难点和技巧

楼主#
更多 发布于:2009-05-20 16:57
<P ><B >一、<FONT face="Times New Roman"> </FONT></B><B >基本步骤</B></P>
<P ><FONT face="Times New Roman">1</FONT>、安装<FONT face="Times New Roman">GoogleEarth</FONT>程序</P>
<P ><FONT face="Times New Roman">2</FONT>、对<FONT face="Times New Roman">GoogleEarth activex</FONT>控件进行注册(<FONT face="Times New Roman">googleearth.exe /regserver</FONT>)</P>
<P ><FONT face="Times New Roman">3</FONT>、在开发环境中引用<FONT face="Times New Roman">googleearth activex</FONT></P>
<P ><FONT face="Times New Roman"></FONT> </P>
<P ><B >二、<FONT face="Times New Roman"> </FONT></B><B >开发方式</B></P>
<P >针对<FONT face="Times New Roman">GE</FONT>的开发有两种方式,一种是基于<FONT face="Times New Roman">GE</FONT>的<FONT face="Times New Roman">com API</FONT>,一种是基于<FONT face="Times New Roman">KML</FONT>。基于<FONT face="Times New Roman"> Com API</FONT>的开发方式主要用来控制<FONT face="Times New Roman">GE</FONT>的视角、实现动画效果,而基于<FONT face="Times New Roman">KML</FONT>的开发方式主要用来生成地理要素,实现数据的动态更新等。在实际应用中,需要结合这两种开发方式,这样才能得到比较理想的效果。</P>
<P ><B ><FONT face="Times New Roman">1、 </FONT></B><B >基于<FONT face="Times New Roman">ComAPI</FONT></B><B >的开发</B></P>
<P ><FONT face="Times New Roman">GE </FONT>公布的<FONT face="Times New Roman">API</FONT>目前是<FONT face="Times New Roman">1.0a</FONT>版,数量比较少,所能实现的功能也不多,在实际开发中主要用来加载<FONT face="Times New Roman">KML</FONT>数据、控制视角和实现动画播放。</P>
<P ><FONT face="Times New Roman">A、 </FONT>加载<FONT face="Times New Roman">KML</FONT>数据</P>
<P ><B ><FONT face="Times New Roman">IApplicationGE.</FONT></B><B > <a href="http://earth.google.com/comapi/interfaceIApplicationGE.html#0c3cf6e34051aab573a7fb82eb3f4a41" target="_blank" >OpenKmlFile</A>(kmlFilePath),</B>加载指定的kml文件到GE中;</P>
<P ><B ><FONT face="Times New Roman">IApplicationGE.</FONT></B><B ><a href="http://earth.google.com/comapi/interfaceIApplicationGE.html#228bef8322f9243b48a356da39218d5a" target="_blank" >LoadKmlData</A>(kmlData)</B>,加载kml文本流到GE中</P>
<P ><FONT face="Times New Roman">B、 </FONT>控制视角</P>
<P ><B ><FONT face="Times New Roman">IApplicationGE. </FONT></B><B ><a href="http://earth.google.com/comapi/interfaceIApplicationGE.html#e16c1950c69eb41e505e24626fe9077e" target="_blank" >SetCamera</A></B><B >(</B><B ><a href="http://earth.google.com/comapi/interfaceICameraInfoGE.html" target="_blank" >ICameraInfoGE</A> </B><B >,</B><B >double </B><B >)</B>,设置GE当前的视角,第一个参数为视角参数,第二个参数为当前视角飞到这个视角的速度(取值范围为0--5);</P>
<P ><B ><FONT face="Times New Roman">IApplicationGE</FONT></B><B > .<a href="http://earth.google.com/comapi/interfaceIApplicationGE.html#5e0e010324df860e1cdd8f26564b35df" target="_blank" >SetFeatureView</A>(<a href="http://earth.google.com/comapi/interfaceIFeatureGE.html" target="_blank" >IFeatureGE</A>,double)</B>,从当前视角飞到指定要素处的视角,第一个参数为指定的要素,这个要素的视角由KML中的<LookAt>标签来决定,第二个参数为飞行速度(取值范围为0—5)。</P>
<P ><FONT face="Times New Roman">C、 </FONT>动画效果</P>
<P ><FONT face="Times New Roman">GE</FONT>中实现动画效果有两种方法,第一种是通过<FONT face="Times New Roman">KML</FONT>中的<FONT face="Times New Roman"><Annimation></FONT>标签来实现,这个标签内部放置的是每一帧所代表的视图,第二种方式是通过<FONT face="Times New Roman">API</FONT>来实现某个父要素下的所有子要素的视图的轮流切换。</P>
<P ><B ><a href="http://earth.google.com/comapi/interfaceITimeIntervalGE.html" target="_blank" >ITimeIntervalGE</A>.Play()</B> 开始播放<FONT face="Times New Roman"><Annimation></FONT>标签中的帧</P>
<P ><B ><FONT face="Times New Roman">ITourControllerGE.</FONT></B><B > <a href="http://earth.google.com/comapi/interfaceITourControllerGE.html#121370f2ce2efbc11b681222d910c268" target="_blank" >PlayOrPause</A> ()</B> 播放某个父要素下的子要素,或暂停播放</P>
<P ><B ><FONT face="Times New Roman">2、 </FONT></B><B >基于</B><B ><FONT face="Times New Roman">KML</FONT></B><B >的开发</B><B ></B></P>
<P ><FONT face="Times New Roman">GE</FONT>实际上就是一个浏览器,被浏览的数据是<FONT face="Times New Roman">KML</FONT>,<FONT face="Times New Roman">KML</FONT>和<FONT face="Times New Roman">GML</FONT>、<FONT face="Times New Roman">SVG</FONT>等表示矢量图形的标准类似,不过他所描述的是三维的数据结构,可以认为<FONT face="Times New Roman">KML</FONT>是基于<FONT face="Times New Roman">XML</FONT>的一种三维矢量图形标准。</P>
<P ><FONT face="Times New Roman">KML</FONT>的结构组成可以参考(<FONT face="Times New Roman">http://code.google.com/apis/kml/documentation/kml_tags_beta1.html</FONT>)<FONT face="Times New Roman">,</FONT>从其结构图中可以看出,<FONT face="Times New Roman">KML</FONT>描述地物的方式和通用的<FONT face="Times New Roman">GIS</FONT>相类似,主要由要素、样式、视角、动画等部分组成。下面我说明<FONT face="Times New Roman">KML</FONT>中几个比较有难度的技术。</P>
<P ><FONT face="Times New Roman"><B >A、      </B><B >LOD</B></FONT><B >技术</B><B ></B></P>
<P ><FONT face="Times New Roman">LOD</FONT>(Level Of Detail)地图分级加载技术,利用<FONT face="Times New Roman">LOD</FONT>技术可以在<FONT face="Times New Roman">PC</FONT>机上浏览海量的影像地图数据。有<FONT face="Times New Roman">GIS</FONT>平台使用经验的都知道,我们可以设置某个图层在某个比例尺范围之内显示,小于或者超过这个范围则不显示。<FONT face="Times New Roman">LOD</FONT>技术非常类似,比如说,在视角高度很大的时候,我只加载<FONT face="Times New Roman">1</FONT>:<FONT face="Times New Roman">5000W</FONT>的影像数据,在视角高度很小的时候,我只加载<FONT face="Times New Roman">1</FONT>:<FONT face="Times New Roman">1000</FONT>的数据,这样的话,视角高度越低,我们所能看到的地物越详细。</P>
<P >在<FONT face="Times New Roman">KML</FONT>中用来实现<FONT face="Times New Roman">LOD</FONT>技术的是<FONT face="Times New Roman"><Region></FONT>标签,这个标签定义了在什么范围内,在什么像素级别范围内显示某个要素。</P>
<P ><B ><FONT face="Times New Roman">B、</FONT></B><B >动态数据更新技术</B><B ></B></P>
<P >在<FONT face="Times New Roman">GPS</FONT>车辆监控系统中,需要对实时数据进行更新。利用<FONT face="Times New Roman">KML</FONT>中的<FONT face="Times New Roman"><NetworkLink></FONT>和<FONT face="Times New Roman">< refreshMode></FONT>标签可以实现数据的实时更新。将<FONT face="Times New Roman">refreshMode</FONT>设置为<FONT face="Times New Roman">onInterval</FONT>模式,并在<FONT face="Times New Roman">< refreshInterval ></FONT>中设置间隔时间,那么<FONT face="Times New Roman">GE</FONT>将间隔指定的时间来刷新一下<FONT face="Times New Roman"><href></FONT>标签中的链接地址,这个链接地址可以是本地磁盘上的一个文件,也可以是一个网络链接。(可以参照<FONT face="Times New Roman">gpsrealtime.kml</FONT>来理解)</P>
<P ><B ><FONT face="Times New Roman">C、      </FONT></B><B >动画播放技术</B><B ></B></P>
<P ><FONT face="Times New Roman">KML</FONT>中的<FONT face="Times New Roman">< TimeSpan ></FONT>或者<FONT face="Times New Roman"><</FONT><B> </B>TimeStamp<FONT face="Times New Roman"> ></FONT>标签是用来控制动画播放的,<FONT face="Times New Roman">< TimeSpan ></FONT>或<FONT face="Times New Roman"><</FONT><B> </B>TimeStamp<FONT face="Times New Roman"> ></FONT>都必须包含在在一个要素标签内,表示的是在某个时间点上,<FONT face="Times New Roman">GE</FONT>的视图转到当前要素标签所规定的视图上,并完成相应的动作。因此每一个包含时间戳标签的要素标签都表示动画过程中的一帧。(可以参照<FONT face="Times New Roman">trackreplay.kml</FONT>来理解)</P>
<P ><B ><FONT face="Times New Roman">D、      </FONT></B><B >三维建模技术</B><B ></B></P>
<P ><FONT face="Times New Roman">KML</FONT>中的几何对象都包含三个属性:<FONT face="Times New Roman">longitude</FONT>、<FONT face="Times New Roman">latitude</FONT>、<FONT face="Times New Roman">altitude</FONT>,利用基本的几何图形(如点、线、面),加上高程数据,我们可以构建一些简单的三维图形。如果需要构建复杂的三维模型,可以借助三维建模工具,如<FONT face="Times New Roman">3D max</FONT>,<FONT face="Times New Roman">google sketch,AutoCAD,</FONT>然后将得到的三维模型转成<FONT face="Times New Roman">dae</FONT>格式即可,这样就可以直接在<FONT face="Times New Roman">GE</FONT>中调用这些三维模型了(利用<FONT face="Times New Roman"><</FONT><A><FONT color=#bf8017>Model</FONT></A><FONT face="Times New Roman">></FONT>标签来引用模型文件的位置)</P>
<P ><B >三、几个技巧</B><B ><FONT face="Times New Roman"> </FONT></B></P>
<P ><FONT face="Times New Roman">1</FONT>、如何将<FONT face="Times New Roman">GE</FONT>的地图控件引用到自定义的窗体中?</P>
<P ><FONT face="Times New Roman">         </FONT>在一般情况下,我们针对<FONT face="Times New Roman">GE</FONT>的开发都只能基于<FONT face="Times New Roman">GE</FONT>程序本身来进行,所有的操作都必须在<FONT face="Times New Roman">GE</FONT>本身的框架上进行,不能将<FONT face="Times New Roman">GE</FONT>的地图控件像一般可拖放的控件来操作。怎么解决这个问题呢,这里要用到一下<FONT face="Times New Roman">Win API</FONT>,将<FONT face="Times New Roman">GE</FONT>中的地图部分<FONT face="Times New Roman">hook</FONT>过来。</P>
<P ><FONT face="Times New Roman">            </FONT><FONT face="Times New Roman"><FONT color=#ff6600>this._GEMainHandler = (IntPtr)this._googleEarth.GetMainHwnd();//</FONT></FONT>获取<FONT face="Times New Roman">GE</FONT>程序的句柄</P>
<P ><FONT face="Times New Roman">            <FONT color=#ff6600>SetWindowPos((int)this._GEMainHandler, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE + SWP_HIDEWINDOW)</FONT><FONT color=#ff6600>;//</FONT></FONT>将<FONT face="Times New Roman">GE</FONT>窗体移到屏幕可视范围之外,使之不可见</P>
<P ><FONT face="Times New Roman">          <FONT color=#ff6600>  </FONT><FONT color=#ff6600>this._GEHrender = (IntPtr)_googleEarth.GetRenderHwnd();</FONT><FONT color=#ff6600>//</FONT></FONT>获取<FONT face="Times New Roman">GE</FONT>的地图控件的句柄</P>
<P ><FONT face="Times New Roman">           <FONT color=#ff6600> </FONT><FONT color=#ff6600>this._GEParentHrender = GetParent(this._GEHrender);</FONT><FONT color=#ff6600>//</FONT></FONT>获取<FONT face="Times New Roman">GE</FONT>地图控件的父控件的句柄</P>
<P ><FONT face="Times New Roman">          <FONT color=#ff6600>  </FONT><FONT color=#ff6600>PostMessage((int)this._GEParentHrender, WM_HIDE, 0, 0);</FONT><FONT color=#ff6600>//</FONT></FONT>发送消息到地图控件的父控件,使之不可见</P>
<P ><FONT face="Times New Roman">            <FONT color=#ff6600>SetParent(this._GEHrender, customControl.Handle);</FONT><FONT color=#ff6600>//</FONT></FONT>将<FONT face="Times New Roman">GE</FONT>地图控件的父控件设置为我们指定的控件</P>
<P ><FONT face="Times New Roman"></FONT> </P>
<P >使用上面的代码,我们就可以将<FONT face="Times New Roman">GE</FONT>中的地图控件抢夺到我们自己的<FONT face="Times New Roman">winform</FONT>中。(参考<FONT face="Times New Roman">utilities\GEHandler.cs</FONT>)</P>
<P ><FONT face="Times New Roman"></FONT> </P>
<P ><FONT face="Times New Roman">2</FONT>、如何为<FONT face="Times New Roman">GE</FONT>提供动态数据?</P>
<P ><FONT face="Times New Roman">   </FONT>为<FONT face="Times New Roman">GE</FONT>提供动态数据,需要用到上面介绍的<FONT face="Times New Roman">KML</FONT>动态数据更新技术。在这里提供一个比较好的解决方案,架构动态数据提供服务器。这有点类似于<FONT face="Times New Roman">B/S</FONT>架构,<FONT face="Times New Roman">browser</FONT>就是<FONT face="Times New Roman">GE</FONT>,<FONT face="Times New Roman">Server</FONT>就是我们要架设的服务器,<FONT face="Times New Roman">Server</FONT>提供的是动态的符合<FONT face="Times New Roman">KML</FONT>规范的数据,<FONT face="Times New Roman">GE</FONT>间隔一定时间去服务器上获取一下数据。</P>
<P ><FONT face="Times New Roman"></FONT> </P>
<P ><FONT face="Times New Roman">3、    </FONT>如何得到<FONT face="Times New Roman">GE</FONT>中的指定要素?</P>
<P >当我们需要对某个要素进行操作时,首先必须得到这个要素。当<FONT face="Times New Roman">KML</FONT>文件被加载进入<FONT face="Times New Roman">GE</FONT>中后,这个文件也被当作一个要素看待,文件中的这个几何图形、图片、链接等都被当成这个要素的子要素看待。在<FONT face="Times New Roman">GE</FONT>中获取某个要素只有两个途径:通过要素名称和通过要素的链接地址</P>
<P ><a href="http://earth.google.com/comapi/interfaceIApplicationGE.html#7eed0b83b35888b19ba08c76817dde5c" target="_blank" ><B>GetFeatureByName</B></A>(name)通过要素名称来得到要素</P><a href="http://earth.google.com/comapi/interfaceIApplicationGE.html#f0305e1a362905411a33c31ec82d012b" target="_blank" ><B>GetFeatureByHref</B></A>(href)通过链接地址来得到要素(得到的是从链接地址中代表的内容)
喜欢0 评分0
whmwxhanshan123
路人甲
路人甲
  • 注册日期2006-06-17
  • 发帖数3108
  • QQ
  • 铜币6445枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2009-05-21 10:56
<img src="images/post/smile/dvbbs/em01.gif" />
举报 回复(0) 喜欢(0)     评分
aqi0530
路人甲
路人甲
  • 注册日期2008-06-28
  • 发帖数10
  • QQ
  • 铜币88枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2009-09-24 12:14
<img src="images/post/smile/dvbbs/em04.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
举报 回复(0) 喜欢(0)     评分
游客

返回顶部