提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 一、QT5.9在vs上部署
    • 1.1 在Vs中下载插件
    • 1.2 配置QT
  • 二、OsgEarth3.2环境配置。
  • 三、在QT中配置OsgEarth3.2
  • 四、在QT环境中利用osgEarth3.2加载shp文件。
  • 总结

前言

经过两个星期,从osg零基础,配置好osgearth和qt集成,并加载好shp文件, 本着记录自己学习的状态,做好笔记,提升自己对代码的熟悉状态写下本文,希望对大家有所帮助。


提示:以下是本篇文
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 一、QT5.9在vs上部署
    • 1.1 在Vs中下载插件
    • 1.2 配置QT
  • 二、OsgEarth3.2环境配置。
  • 三、在QT中配置OsgEarth3.2
  • 四、在QT环境中利用osgEarth3.2加载shp文件。
  • 总结

提示:以下是本篇文章正文内容,下面案例可供参考

一、QT5.9在vs上部署

如何在Vs中安装QT,并完成部署环境。

https://www.bilibili.com/video/BV1AX4y1w7Nt?spm_id_from=333.999.0.0
根据B站上的视频,进行完成部署qt。

1.1 在Vs中下载插件

打开 Visual Studio ,在拓展->管理拓展->联机->搜索 qt ,然后下载.下载完毕后关闭 VS ,此时弹出安装界面,选择安装即可。

1.2 配置QT

当插件下载完成时,Vs状态栏上方会出现 Qt VS Tools 工具按钮。

点击Qt Versions,配置QT路径。
路径根据你Qt上下载Vs版本进行加载即可。

配置完成后,就可以创建QT应用程序了。

二、OsgEarth3.2环境配置。

OSG中文社区里面有很多教程。
我这里将osg公开资源以网盘形式分享给大家。
链接:https://pan.baidu.com/s/13aenl-NqkXRrl40luNwnzg
提取码:539f

下载文件后,打开编译好的库。
里面有详细教程

三、在QT中配置OsgEarth3.2

这一步花了我大半时间,终于在一位大佬的博客中得到解决,谢谢大哥!
https://blog.csdn.net/ambition_xiaoman/article/details/118609661
大家可以自行查看。

配置好的qt大概是这种的

能够加载出地球即可

四、在QT环境中利用osgEarth3.2加载shp文件。

其中在QT环境配置好osgearth加载shp文件,网上有很多很多例子,但都是osgearth2.10的,但是osgearth2.1在qt上集成环境的例子好像没有,查了很多很多教程和网站都没有,我就根据osgEarth2.10的例子根据其帮助文档进行书写最终完成。

代码如下(示例):

//头文件
#pragma once#include <QtWidgets/QMainWindow>
#include "ui_osg32qt.h"
#include "GraphicsWindowQt.h"#include <QTimer>
#include <osg/Notify>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osg/Group>
#include <osg/Node>
#include <osg/Camera>
#include <osg/PositionAttitudeTransform>
#include <osgGA/TrackballManipulator>
#include <osgGA/StateSetManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/Viewer>#include <osgEarth/MapNode>
#include <osgEarth/GDAL>
#include <osgEarth/ExampleResources>
#include <osgEarth/EarthManipulator>
#include <osgEarth/SpatialReference>#include <osgEarth/GeoTransForm>
#include <osgEarth/GeoCommon>#include <osgEarth/Ephemeris>
#include <osgEarth/Sky>#include <osgUtil/Tessellator>
#include <osgEarth/GLUtils>
#include <osg/Geode>
#include <osg/Geometry>//要素类
#include <osgEarth/Style>
#include <osgEarth/OGRFeatureSource>
#include <osgEarth/FeatureModelLayer>
#include <osgEarth/FeatureImageLayer>#include <QList>
#include <QGroupBox>
#include <ctime>
#include <QStatusBar>
#include <QCheckBox>
#include <QPushButton>
#include <QSpinBox>
#include <QLineEdit>class osg32qt : public QMainWindow
{Q_OBJECTpublic:osg32qt(QWidget *parent = Q_NULLPTR);~osg32qt();
private:Ui::osg32qtClass ui;private:QTimer* _timer;     // 计时器,每5ms触发一次事件osgViewer::Viewer* viewer;osg::ref_ptr<osg::Group> root;osg::ref_ptr<osg::Camera> camera;osg::ref_ptr<osg::Node> earthNode;osg::ref_ptr<osgEarth::MapNode> mapNode;osg::ref_ptr<osgEarth::Map> map;osg::ref_ptr <osg::MatrixTransform> earthForm;osg::ref_ptr<osgEarth::EarthManipulator> em;tm* t_tm;osgEarth::SkyNode* m_pSkyNode;time_t now_time;
private:void InitOSG();// 初始化设置osgvoid InitUI();//界面初始化void InitTimer();//屏幕刷新初始化void InitOsgearth();//初始化osgearthvoid InitSky();//天空初始化
private slots:// 定时更新帧的槽函数void updateFrame();};

//cpp文件

#include "osg32qt.h"
#include <osg/TexGen>
osg32qt::osg32qt(QWidget *parent): QMainWindow(parent)
{ui.setupUi(this);InitOSG();InitOsgearth();InitUI();InitTimer();
}
osg32qt::~osg32qt()
{}
void osg32qt::InitOSG()// 初始化设置osg
{viewer = new osgViewer::Viewer;// 设置模型root = new osg::Group;// 显示 .earth 文件中的地球模型//获取屏幕分辨率 长宽osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();if (!wsi)return;unsigned int width, height;wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);//设置图形环境特性osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;traits->windowDecoration = false;//声明是否显示窗口的描述traits->x = 0;traits->y = 0;traits->width = width;traits->height = height;traits->doubleBuffer = true;//创建图形窗口是否使用双缓存//设置照相机camera = new osg::Camera;camera->setGraphicsContext(new osgQt::GraphicsWindowQt(traits.get()));camera->setClearColor(osg::Vec4(0.2, 0.2, 0.6, 1.0));camera->setViewport(new osg::Viewport(0, 0, width, height));camera->setProjectionMatrixAsPerspective(30.0f, (double(traits->width)) / (double(traits->height)), 1.0f, 10000.0f);//设置渲染器viewer->setCamera(camera);viewer->setSceneData(root);viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);//创建为单线程viewer->addEventHandler(new osgGA::StateSetManipulator(viewer->getCamera()->getOrCreateStateSet()));
}
void osg32qt::InitOsgearth()
{//earthNode = new osg::Node;//earthNode = osgDB::readNodeFile("./feature_labels.earth");//从底图影像图层开始;我们将使用 GDAL 驱动程序加载本地 GeoTIFF 文件:map = new osgEarth::Map();osgEarth::GDALImageLayer* basemap = new osgEarth::GDALImageLayer();basemap->setURL("G:\\QT\\osgt\\osgearth-3.2\\data\\world.tif");map->addLayer(basemap);//接下来,我们添加一个图层以提供要素数据。osgEarth::OGRFeatureSource* features = new osgEarth::OGRFeatureSource();features->setURL("G:\\QT\\osgt\\osgearth-3.2\\data\\world.shp");//features->setURL()map->addLayer(features);//定义要素数据的样式。由于我们将渲染矢量作为线,配置线符号化器:osgEarth::Style style;//可见性osgEarth::RenderSymbol* rs = style.getOrCreate<osgEarth::RenderSymbol>();rs->depthTest() = false;//贴地设置osgEarth::AltitudeSymbol* alt = style.getOrCreate<osgEarth::AltitudeSymbol>();alt->clamping() = alt->CLAMP_TO_TERRAIN;alt->technique() = alt->TECHNIQUE_DRAPE;osgEarth::LineSymbol* ls = style.getOrCreateSymbol<osgEarth::LineSymbol>();ls->stroke()->color() = osgEarth::Color::Yellow;ls->stroke()->width() = 2.0f;ls->tessellationSize()->set(100, osgEarth::Units::KILOMETERS);osgEarth::PolygonSymbol * polygonsymol = style.getOrCreateSymbol<osgEarth::PolygonSymbol>();polygonsymol->fill()->color() = osgEarth::Color(152.0f / 255, 251.0f / 255, 152.0f / 255, 0.8f); //238 230 133polygonsymol->outline() = true;//将要素的路径添加到图层里osgEarth::FeatureImageLayer* layer = new osgEarth::FeatureImageLayer();layer->setFeatureSource(features);//将style风格加载到图层中osgEarth::StyleSheet* sheet = new osgEarth::StyleSheet();sheet->addStyle(style);layer->setStyleSheet(sheet);map->addLayer(layer);osgEarth::LayerVector layers;map->getLayers(layers);for (osgEarth::LayerVector::const_iterator i = layers.begin(); i != layers.end(); ++i){osgEarth::Layer* layer = i->get();if (layer->getStatus().isError() &&layer->getEnabled()){OE_WARN << layer->getName() << " : " << layer->getStatus().toString() << std::endl;}}mapNode = new  osgEarth::MapNode(map.get());//mapnode初始化//mapNode = osgEarth::MapNode::findMapNode(earthNode.get());//优化场景数据earthForm = new osg::MatrixTransform;//osgearth操作器 用来设置osgearhem = new osgEarth::Util::EarthManipulator;if (mapNode.valid()){em->setNode(mapNode);}em->getSettings()->setArcViewpointTransitions(true);//设置osg渲染窗口viewer->setCameraManipulator(em);//获取地球半径 设置视点//double earth_R = mapNode->getMap()->getSRS()->getEllipsoid()->getRadiusEquator();const char* viewPointName = QString::fromLocal8Bit("北京").toStdString().c_str();//em->setViewpoint(osgEarth::Viewpoint(viewPointName, 112.44, 33.75, 0.0, 0.0, -90.0, 5 * earth_R), 5);//初始化天空InitSky();
}
void osg32qt::InitSky()
{//获取当前时间 初始化天空now_time = time(0);t_tm = localtime(&now_time);osgEarth::DateTime cur_date_time(now_time);osgEarth::Ephemeris* ephemeris = new osgEarth::Ephemeris;//设置黑夜明暗程度osgEarth::Util::SkyOptions skyOptions;skyOptions.ambient() = 0.3;m_pSkyNode = osgEarth::SkyNode::create(skyOptions);m_pSkyNode->setName("SkyNode");m_pSkyNode->setEphemeris(ephemeris);m_pSkyNode->setDateTime(cur_date_time);viewer->setLightingMode(osg::View::SKY_LIGHT);m_pSkyNode->attach(viewer, 0);m_pSkyNode->setLighting(true);//添加到场景m_pSkyNode->addChild(mapNode);root->addChild(m_pSkyNode);}
void osg32qt::InitUI()//界面初始化
{//osg 与 qt链接osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>(camera->getGraphicsContext());//ui布局ui.horizontalLayout->addWidget((QWidget*)(gw->getGLWidget()));//QWidget* osg_widget = (QWidget*)(gw->getGLWidget());//this->setCentralWidget(osg_widget);//窗口最大化this->setWindowState(Qt::WindowMaximized);this->setWindowTitle(QString::fromLocal8Bit("数字地球"));
}
void osg32qt::InitTimer()//屏幕刷新初始化
{_timer = new QTimer;QObject::connect(_timer, SIGNAL(timeout()), this, SLOT(updateFrame()));_timer->start(10);}
void osg32qt::updateFrame()
{viewer->frame();
}

效果图:


# 五、示例程序可自取 https://download.csdn.net/download/weixin_44413499/46987576

总结

OsgEarth3.2相关教程特别少,现在网络上大多都是osgEarth2.10的版本,因为我配置OsgEarth2.10和qt的环境出了一些问题,不然也不会用OsgEarth3.2了,继续加油。

在Vs2017上集成osgearth3.2和qt5.9,并加载shp文件。相关推荐

  1. Qt5 使用 #pragma 加载 lib 文件的注意事项

    --------------------------------------------- -- 时间:2018-12-06 -- 创建人:Ruo_Xiao -- Qt5.2.1 和 VS2010 - ...

  2. python bottle web框架上传静态文件与加载静态文件

    文章目录 1 上传文件 2 加载静态文件 1 上传文件 # 上传文件 @route('/upload', method=['POST','GET']) def upload():f = request ...

  3. iOS CocoaPods第三方库加载本地文件或服务器上的zip文件(二)

    本篇文章重点介绍,如何加载zip文件压缩包第三方库.如果伙伴们想了解如何加载本地文件请自行翻看上篇文件. 方案: 不废话,直接上代码!编辑我们的WechatOpenSDK.podspec文件: Pod ...

  4. Nuxtjs上使用wow.js+animate.css实现滚动加载动画

    最近做个官网(技术栈使用Nuxt)需要用到滑动到可视区域才触发动画效果,几乎所有的页面都要"动"起来,手写要累死的节奏,赶紧寻找工具!发现wow.js+animate.css可以满 ...

  5. Nignx集成fastDFS后访问Nginx一直在加载中解决

    问题描述: Nginx集成fastDFS后,访问Nginx一直在加载中,得不到页面.查看Nginx的错误日志: 可以看到是fastdfs.conf的配置错误,tracker的ip没有修改: fastd ...

  6. 用户从服务器上获取信息资源,从服务器端获取资源动态加载到场景.docx

    从服务器端获取资源动态加载到场景 [unity3d]从服务器端获取资源动态加载到场景分类:编程语言/C语言/文章我们的游戏制作完发布出去提供给玩家,为了给玩家带来更好的游戏体验,要做各种的优化以及设计 ...

  7. Linux上搭建h2引擎加载h2文件

    问题背景   因为排查canal问题,需要打开linux上部署的canal的对应的h2.mv.db文件 查了一下,原来h2官方就有这种引擎,可以加载对应的h2文件,实际上就canal的lib目录下有对 ...

  8. php ajax 上拉显示更多,PHP+Ajax点击加载更多内容 -这个效果好,速度快,只能点击更多加载,不能滚动自动加载...

    这个效果好,速度快,只能点击更多加载,不能滚动自动加载 一.HTML部分 ::点击加载更多内容:: 引入jQuery插件和jquery.more.js加载更多插件 jQuery $(function( ...

  9. 第61篇一对多之老师端私有白板点击上共享白板及老师端学生私有白板加载多次及点头像出私有白板列表周四

    关键词:老师端私有白板点击上共享白板,老师端学生私有白板加载多次,点头像出私有白板列表 一.私有白板向老师端传图片数据 1.1 服务器运行平台 老师端:https://localhost:9101/d ...

最新文章

  1. qq邮箱mx服务器,电子邮箱如何设置域名MX记录
  2. apache 定义日志格式 及日志记录
  3. 使用后期处理效果实现运动模糊
  4. 中石油训练赛 - Racing Gems(最长不下降子序列)
  5. IO多路复用原理剖析
  6. 多台电脑共用一个耳机、音箱
  7. iOS UIWebView加载网页、文件、HTML
  8. 程序员们之间的“鄙视链”,程序员底之间无声的战争
  9. 使用 gradle 在编译时动态设置 Android resValue / BuildConfig / Manifes中lt;meta-datagt;变量的值...
  10. iphone屏幕录制_苹果6s有屏幕录制吗
  11. GoLang 插件化开发
  12. 关于EXCEL打开VBA时发生vbe6ext.olb不能被加载及内 存溢出错误的解决方法
  13. 手机号已经绑定微信号,现在怎么再注册一个微信号
  14. c语言密码锁程序,简易密码锁(C语言程序).doc
  15. 自然数拆分(回溯法)
  16. 盒子模型属性详解及案例
  17. 苹果屏幕自动变暗_苹果iOS 14震撼发布 全新功能对标安卓
  18. 14晶体三极管的三个工作区域
  19. cocos2dx[2.x](14)--音乐音效SimpleAudioEngine
  20. 扬州大学广陵学院计算机科学与技术女生多吗,超激动!萌新们纷纷晒出与扬大录取通知书合照...

热门文章

  1. nohup java_解析nohup java -jar xxx
  2. IDEA报错 Cannot resolve method ‘xxx‘ in ‘xxx‘
  3. tiny4412 裸机程序 九、串口排查驱动原因及字符图片显示
  4. 仿网易云音乐Android端歌手资料页面的实现
  5. 英语句子成分分析(二)--十大词类
  6. 杂谈---名言警句记录
  7. Java学习笔记(9)-数组
  8. 数据库关于事务的详解分析(全)包含面试常问的细节
  9. 闭关修炼(十二) NIO
  10. java模拟内存溢出并分析_本地模拟内存溢出并分析Dump文件