1. 概述

osgEarth支持.earth格式的文件,里面保存了数字地球相关信息的配置XML,只需要读取这个配置文件,就可以直接得到相应的数字地球相关效果。但实际使用中还是感觉到有些不便,有些效果没办法保存下来,所以很多时候还是使用代码实现比较好。osgEarth最基础的就是显示一个数字地球了。

2. 实现

2.1. 三维显示

具体的实现代码如下:

#include <Windows.h>
#include <iostream>
#include <string> #include <osgViewer/Viewer>
#include <osgDB/ReadFile> #include <osgEarth/MapNode> #include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/cache_filesystem/FileSystemCache>
#include <osgEarth/ImageLayer> #include <osgEarthUtil/EarthManipulator> using namespace std; int main()
{
osgEarth::ProfileOptions profileOpts; //地图配置:设置缓存目录
osgEarth::Drivers::FileSystemCacheOptions cacheOpts;
string cacheDir = "D:/Work/OSGNewBuild/tmp";
cacheOpts.rootPath() = cacheDir; //
osgEarth::MapOptions mapOpts;
mapOpts.cache() = cacheOpts;
mapOpts.profile() = profileOpts; //创建地图节点
osg::ref_ptr<osgEarth::Map> map = new osgEarth::Map(mapOpts);
osg::ref_ptr<osgEarth::MapNode> mapNode = new osgEarth::MapNode(map); osgEarth::Drivers::GDALOptions gdal;
gdal.url() = "D:/Work/OSGNewBuild/osgearth-2.10.1/data/world.tif";
osg::ref_ptr<osgEarth::ImageLayer> layer = new osgEarth::ImageLayer("BlueMarble", gdal);
map->addLayer(layer); osgViewer::Viewer viewer;
viewer.setSceneData(mapNode); osg::ref_ptr< osgEarth::Util::EarthManipulator> mainManipulator = new osgEarth::Util::EarthManipulator;
viewer.setCameraManipulator(mainManipulator); viewer.setUpViewInWindow(100, 100, 800, 600); return viewer.run();
}

这里有两个点值得注意,其一是使用了缓存机制,可以在浏览的时候变浏览边生成缓存,所以设置了一个缓存目录;其二是加载了一个底图数据,是osgEarth中自带的。运行的效果如下:

2.2. 二维显示

除了显示三维数字地球之外,osgEarth其实还可以显示成平面地图,只需要设置具体的参数就可以了。例如这里显示成web墨卡托投影的二维平面地图:

#include <Windows.h>
#include <iostream>
#include <string> #include <osgViewer/Viewer>
#include <osgDB/ReadFile> #include <osgEarth/MapNode> #include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/cache_filesystem/FileSystemCache>
#include <osgEarth/ImageLayer> #include <osgEarthUtil/EarthManipulator> #include <gdal_priv.h> using namespace std; int main()
{
CPLSetConfigOption("GDAL_DATA", "D:/Work/OSGNewBuild/OpenSceneGraph-3.6.4/3rdParty/x64/gdal-data"); string wktString = "EPSG:3857"; //web墨卡托投影
//string wktString = "EPSG:4326"; //wgs84
osgEarth::ProfileOptions profileOpts;
profileOpts.srsString() = wktString; //osgEarth::Bounds bs(535139, 3365107, 545139, 3375107);
//osgEarth::Bounds bs(73, 3, 135, 53);
//profileOpts.bounds() = bs; //地图配置:设置缓存目录
osgEarth::Drivers::FileSystemCacheOptions cacheOpts;
string cacheDir = "D:/Work/OSGNewBuild/tmp";
cacheOpts.rootPath() = cacheDir; //
osgEarth::MapOptions mapOpts;
mapOpts.cache() = cacheOpts;
mapOpts.coordSysType() = osgEarth::MapOptions::CSTYPE_PROJECTED; mapOpts.profile() = profileOpts; //创建地图节点
osg::ref_ptr<osgEarth::Map> map = new osgEarth::Map(mapOpts);
osg::ref_ptr<osgEarth::MapNode> mapNode = new osgEarth::MapNode(map); osgEarth::Drivers::GDALOptions gdal;
gdal.url() = "D:/Work/OSGNewBuild/osgearth-2.10.1/data/world.tif";
osg::ref_ptr<osgEarth::ImageLayer> layer = new osgEarth::ImageLayer("BlueMarble", gdal);
map->addLayer(layer); osgViewer::Viewer viewer;
viewer.setSceneData(mapNode); osg::ref_ptr< osgEarth::Util::EarthManipulator> mainManipulator = new osgEarth::Util::EarthManipulator;
viewer.setCameraManipulator(mainManipulator); viewer.setUpViewInWindow(100, 100, 800, 600); return viewer.run();
}

Web墨卡托投影平面坐标系的EPSG代码是3857,所以只需要直接传入相应的代码就行了。对于比较复杂或者自定义的坐标系,其实也可以直接传入wkt字符串,因为osgEarth是通过GDAL来处理空间坐标参考的,GDAL又是通过proj4来处理空间坐标参考的,所以这个时候需要通过GDAL设置一下环境变量GDAL_DATA(具体可以参见《GDAL坐标转换》)。

显示的效果如下所示:

显然,跟Web墨卡托投影的特性一样,椭球被投影成了方形的平面地图。

osgEarth使用笔记1——显示一个数字地球的更多相关文章

  1. osgEarth使用笔记4——加载矢量数据

    目录 1. 概述 2. 详论 2.1. 基本绘制 2.2. 矢量符号化 2.2.1. 可见性 2.2.2. 高度设置 2.2.3. 符号化 2.2.4. 显示标注 2.3. 其他 3. 结果 4. 问 ...

  2. osgEarth学习笔记(转载)

    osgEarth学习笔记1.        通过earth文件创建图层时,可以指定多个影像数据源和多个高程数据源,数据源的顺序决定渲染顺序,在earth文件中处于最前的在渲染时处于最底层渲染:所以如果 ...

  3. C#.NET学习笔记2---C#.第一个C#程序

    C#.NET学习笔记2---C#.第一个C#程序 技术qq交流群:JavaDream:251572072  教程下载,在线交流:创梦IT社区:www.credream.com 6.第一个C#程序:   ...

  4. The Pragmatic Programmer 读书笔记之中的一个 DRY-Don’t Repeat Youself

     The Pragmatic Programmer读书笔记之中的一个 DRY-Don't Repeat Youself 尽管自己买了非常多软件project方面的书,可是由于时间的问题.一直没有静 ...

  5. OsgEarth开发笔记(一):Osg3.6.3+OsgEarth3.1+vs2019x64开发环境搭建(上)

    前言   OSG研究之后,做地理GIS显示了地球:<项目实战:Qt+OSG教育学科工具之地理三维星球>,这一文章是基于OSG做的,而基于OsgEarth是可以进一步对地球进行深度操作,所以 ...

  6. Unity3D学习笔记2——绘制一个带纹理的面

    目录 1. 概述 2. 详论 2.1. 网格(Mesh) 2.1.1. 顶点 2.1.2. 顶点索引 2.2. 材质(Material) 2.2.1. 创建材质 2.2.2. 使用材质 2.3. 光照 ...

  7. win7系统的右键菜单只显示一个白色框不显示菜单项 解决办法

    如上图所示,桌面或其他大部分地方点击右键菜单,都只显示一个白色框,鼠标移上去才有菜单项看,并且效果很丑 解决办法: 计算机-右键-属性-高级-性能-设置-视觉效果-淡入淡出或滑动菜单到视图,将其前面的 ...

  8. ios显示一个下载banner

    <meta name="apple-itunes-app" content="app-id=432274380" /> 这个标签是告诉iphone的 ...

  9. linux 如何显示一个文件的某几行(中间几行)

    linux 如何显示一个文件的某几行(中间几行) [一]从第3000行开始,显示1000行.即显示3000~3999行 cat filename | tail -n +3000 | head -n 1 ...

随机推荐

  1. chromevue扩展 vue-devtools-master 谷歌vue的扩展程序

    1,在百度网盘中下载压缩包,网盘地址:https://pan.baidu.com/s/1BnwWHANHNyJzG3Krpy7S8A ,密码:xm6s 2,将压缩包解压到F盘,F:\chromeVue ...

  2. Android开发之将Edittext输入弹出的软键盘设置搜索确定键。详细代码,已验证可用。

    1,首先在布局中添加 android:imeOptions="actionSearch 2,然后java代码中设置代码: et_input_password.setOnEditorActio ...

  3. 获取android手机的屏幕分辨率 android开发

    /** * 获取屏幕分辨率 */ private void getResolution() { // TODO Auto-generated method stub Display display = ...

  4. Idea使用方式——创建类模板

    问题:创建类或接口时,要添加自定义的默认注释,比如版本,时间等.每个类修改显然不符合程序员的思路,有没有办法通过定义模板来实现? 使用Idea模板 Idea可听过创建类模板来实现. 功能路径:Sett ...

  5. 【HttpRunner v3.x】笔记—6. 测试用例-teststeps-RunRequest

    之前我们了解了config里的各项参数,今天来了解另一个重要部分--teststeps,在这之前,先看看测试用例的分层模型. 一.测试用例分层模型 一个testcase里(就是一个pytest格式的P ...

  6. 【Gin-API系列】守护进程和平滑重启(八)

    生产环境的API服务我们都会部署在Linux服务器上,为了不受终端状态的影响,启动服务的时候会让服务在后台运行.那么如何让服务在后台运行呢,目前有2种常见的方法. 1.nohub 运行 表示忽略SIG ...

  7. ORA-00119: ORA-00132: 解决办法 -九五小庞

    问题描述: 1. em打开中提示 https://localhost:1158/em/console/database/instance/repDown?target=orclweng&typ ...

  8. Oracle的dbms_random.value(min,max)函数包括边界值吗?数据是如何分布的?

    事先申明下,我的DB环境是Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production,不保证在其它版本下也 ...

  9. 现象:当指定logback的FileNamePattern为日期2020-01-15后,如果有线程不断的往里写log,过了零点文件不会变成下一日2020-01-16,还是会在2020-01-15里继续写 结论:写log的线程不停,文件不会按日子更换。

    logback版本:1.1.11 这个是我实验验证的,昨天我配置了一个logback,然后用两个线程不断往里写log,结果发现到了今天2020-01-16日,log文件还是昨天的logbackCfg. ...

  10. iTextSharp生成PDF文件

    这是一篇简单的教程,所以只涉及一些iTextSharp生成pdf的简单应用,详细教程请搜索iTextSharp进入官网看官方文档(英文版). iTextSharp官方文档:https://itextp ...