免费视频|新人指南|投诉删帖|广告合作|地信网APP下载

查看: 3840|回复: 1
收起左侧

[其他] osgEarth如何加载离线谷歌卫星地图瓦片的源码教程

[复制链接]

6

主题

740

铜板

34

好友

高级工程师

Rank: 9Rank: 9Rank: 9

积分
966
发表于 2015-1-9 09:48 | 显示全部楼层 |阅读模式

说明
本实例演示重新编译bing驱动直接加载本地离线影像瓦片地图。
本实例使用软件版本:osg3.3.1和osgEarth2.5 VC10编译环境(参考osgearth加载谷歌卫星地图的源码案例),vs2010,水经注万能地图下载器。
osgdb_osgearth_bingd.rar (52.96 KB, 下载次数: 0)
osgearthAPI.rar (31.91 KB, 下载次数: 0)
影像瓦片来源“水经注万能地图下载器”。如果没有安装本软件,可以百度“水经注软件”到官方网站下载。

一、下载瓦片数据
启动水经注万能地图下载器,点击“我的下载”,选择“新建任务”,弹出“选择地图类型” 对话框,选择相应的地图类型,点击“确认”,如下图。




弹出“新建任务”对话框





输入全球坐标,由于我们需要导出瓦片数据,为了增加缩放效果,这里我们从1级到8级都勾选上。选择好级别后,点击开始下载。下载完成后会弹出对话框询问是否要立即导出,选择“是”,然后显示“导出图片数据”对话框,如下图所示。




在该对话框中,选择导出“瓦片:Bing Map”,导出级别“1-8”,选择保存路径,点击“输出”按钮导出数据即可。

二、重新编译Bing驱动
新建“osgdb_osgearth_bingd” 动态库项目,如下图所示。




点击“确定”,弹出“应用程序向导”,如下图所示。




点击下一步




选择程序类型“DLL”,点击“完成”。




添加“包含目录”和“库目录”
包含目录设置为“D:\OSG\include”
库目录设置为“D:\OSG\lib“
以上目录路径根据OSG文件位置设定。




附加依赖项
OpenThreads.lib
osgd.lib
osgAnimationd.lib
osgDBd.lib
osgdb_osgearth_feature_ogrd.lib
osgdb_osgearth_feature_tfsd.lib
osgdb_osgearth_feature_wfsd.lib
osgEarthd.lib
osgEarthAnnotationd.lib
osgEarthFeaturesd.lib
osgEarthSymbologyd.lib
osgEarthUtild.lib
osgFXd.lib
osgGAd.lib
osgManipulatord.lib
osgParticled.lib
osgPresentationd.lib
osgShadowd.lib
osgSimd.lib
osgTerraind.lib
osgTextd.lib
osgUtild.lib
osgViewerd.lib
osgVolumed.lib
osgWidgetd.lib




点击“确定“。
根据D:\OSG\src\osgearth_2.5\osgearth_gitgui\src\osgEarthDrivers\bing路径找到Bing驱动源代码,如下图所示。




BingTileSource.cpp中的代码复制粘贴到,刚刚新建的osgdb_osgearth_bingd.cpp中
如下图所示。




下一步改写代码
#include " BingOptions"   改成   #include "osgEarthDrivers/bing/BingOptions"
_debugDirect ( false)    默认为false 改成_debugDirect ( true )
找到getDirectURI()将内容替换成:
return stringify()<<"D:/Test/tt3Bing"<<getLodKey(key)<<"/"<<getQuadKey(key)<<".jpg";
新建
td::string getLodKey(const TileKey& key)
        {
                unsigned int lod = key.getLevelOfDetail()+2;
                std::stringstream sLod;               
                if(lod<10)
                        sLod<<"/L0"<<lod;
                if(lod>=10)
                        sLod<<"/L"<<lod;
                //OE_WARN << LC << "sLod: "<<sLod.str() << std::endl;        
                return sLod.str();
        }

注意:其中“D:/Test/tt3Bing“为下载的瓦片存放路径。
重新生成。
生成成功后可以在osgdb_osgearth_bingd.项目Debug中查看到
文件。

拷贝到OSG的bin目录下,替换掉之前的dll文件。

三、新建osgearth应用程序
新建步奏跟新建动态库类似,只是不再选择“DLL“,选择“控制台应用程序“




设置“包含目录“,”库目录“,”依赖项“跟DLL设置一样。
这里新建了一个名为“osgearthAPI“的控制台应用程序。代码如下
#include "stdafx.h"
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/StateSetManipulator>
#include <osgGA/TrackballManipulator>
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/bing/BingOptions>
#include <osgEarthDrivers/model_feature_geom/FeatureGeomModelOptions>
#include <osgEarthDrivers/feature_ogr/OGRFeatureOptions>
#include <osgEarthDrivers/cache_filesystem/FileSystemCache>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/GeodeticGraticule>
#include <osgEarthUtil/LatLongFormatter>
#include <osgEarthUtil/Controls>
#include <osgEarthUtil/MouseCoordsTool>
#include <osgEarthUtil/AutoClipPlaneHandler>
#include <osg/PositionAttitudeTransform>
#include <osg/Group>
#include <osg/Node>
#include <osgDB/ReadFile>
#include <osgUtil\optimizer>

int _tmain(int argc, _TCHAR* argv[])
{
        osgEarth::Map* map = new osgEarth::Map();
        osg::ref_ptr<osgViewer::Viewer> viewer=new osgViewer::Viewer();
        osg::Group* root = new osg::Group;
        osg::Node* tankNode = NULL;
        osg::Vec3 tankPosit;

//        osgEarth:rivers::GDALOptions gdal;
        osgEarth:rivers::BingOptions bing;
//        gdal.url()="D:/Documents/Visual Studio 2010/Projects/test3/test3/data/world.tif";
//        map->addImageLayer(new osgEarth::ImageLayer("xx",gdal));
        map->addImageLayer(new osgEarth::ImageLayer("xx",bing));

        osgEarth::MapNode* mapNode = new osgEarth::MapNode(map);
        viewer->setSceneData( mapNode );
        viewer->realize();
        return viewer->run();
}




启动程序,运行效果如下图所示。




至此,Osgearth加载本地离线影像瓦片地图案例完成。


文章来自成都水经注:www.arceyes.com


2

主题

779

铜板

3

好友

助理工程师

Rank: 5Rank: 5

积分
160
发表于 2015-1-13 22:54 | 显示全部楼层
太厉害了,,,,,,,,,,
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

在线客服
快速回复 返回顶部 返回列表