当前位置:>GIS服务>GIS技术

osgEarth如何加载离线卫星地图瓦片的源码教程

2016/7/21 15:01:03 0人评论 6118 次

900-150.gif

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

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



弹出“新建任务”对话框



输入全球坐标,由于我们需要导出瓦片数据,为了增加缩放效果,这里我们从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加载本地离线影像瓦片地图案例完成。

推荐阅读:

【免费】免费分享全国省级与市级行政区划啦!

【免费】百度网盘可免费下载全国高清卫星影像啦!

【免费】百度网盘可免费下载全国30米SRTM高程啦!

【免费】免费从网盘下载的影像和高程DEM如何使用?

【说明】如何利用免费地图数据构建一个离线三维地球?

【说明】DAT与IDX格式文件如何打开?

【说明】如何免费下载高清卫星影像地图?

【说明】22.3TB全国1-20级卫星影像终于出炉!

【亲测】干货:全球73.9TB卫星影像是如何下载的?

【说明】《全国12.5米高程DEM原始数据2.0》发布!

【说明】12.5m、30m、90m 高程数据详细对比说明!

【Cesium】在开源地球 Cesium 离线加载影像和高程!

【ArcMap】在ArcMap中离线加载海量卫星影像的方法!

【说明】《地图发布服务中间件》for Linux 发布!

【GoogleMap API for JS】最新版GoogleMap API 离线源码下载技术!

【亲测】全球卫星影像的大字体挂图打印制作方法

长按关注水经注,我们与你更近一步

地图下载|地图发布|系统部署|定制研发

请拔打24小时热线:400-028-0050

分享到:

相关资讯

    暂无相关的资讯...