日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2023/12/14 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在Vs2017上集成osgearth3.2和qt5.9,并加载shp文件。 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

提示:文章寫(xiě)完后,目錄可以自動(dòng)生成,如何生成可參考右邊的幫助文檔

文章目錄

  • 前言
  • 一、QT5.9在vs上部署
    • 1.1 在Vs中下載插件
    • 1.2 配置QT
  • 二、OsgEarth3.2環(huán)境配置。
  • 三、在QT中配置OsgEarth3.2
  • 四、在QT環(huán)境中利用osgEarth3.2加載shp文件。
  • 總結(jié)


前言

經(jīng)過(guò)兩個(gè)星期,從osg零基礎(chǔ),配置好osgearth和qt集成,并加載好shp文件, 本著記錄自己學(xué)習(xí)的狀態(tài),做好筆記,提升自己對(duì)代碼的熟悉狀態(tài)寫(xiě)下本文,希望對(duì)大家有所幫助。


提示:以下是本篇文
提示:文章寫(xiě)完后,目錄可以自動(dòng)生成,如何生成可參考右邊的幫助文檔

文章目錄

  • 前言
  • 一、QT5.9在vs上部署
    • 1.1 在Vs中下載插件
    • 1.2 配置QT
  • 二、OsgEarth3.2環(huán)境配置。
  • 三、在QT中配置OsgEarth3.2
  • 四、在QT環(huán)境中利用osgEarth3.2加載shp文件。
  • 總結(jié)


提示:以下是本篇文章正文內(nèi)容,下面案例可供參考

一、QT5.9在vs上部署

如何在Vs中安裝QT,并完成部署環(huán)境。

https://www.bilibili.com/video/BV1AX4y1w7Nt?spm_id_from=333.999.0.0
根據(jù)B站上的視頻,進(jìn)行完成部署qt。

1.1 在Vs中下載插件

打開(kāi) Visual Studio ,在拓展->管理拓展->聯(lián)機(jī)->搜索 qt ,然后下載.下載完畢后關(guān)閉 VS ,此時(shí)彈出安裝界面,選擇安裝即可。

1.2 配置QT

當(dāng)插件下載完成時(shí),Vs狀態(tài)欄上方會(huì)出現(xiàn) Qt VS Tools 工具按鈕。

點(diǎn)擊Qt Versions,配置QT路徑。
路徑根據(jù)你Qt上下載Vs版本進(jìn)行加載即可。

配置完成后,就可以創(chuàng)建QT應(yīng)用程序了。

二、OsgEarth3.2環(huán)境配置。

OSG中文社區(qū)里面有很多教程。
我這里將osg公開(kāi)資源以網(wǎng)盤(pán)形式分享給大家。
鏈接:https://pan.baidu.com/s/13aenl-NqkXRrl40luNwnzg
提取碼:539f

下載文件后,打開(kāi)編譯好的庫(kù)。
里面有詳細(xì)教程

三、在QT中配置OsgEarth3.2

這一步花了我大半時(shí)間,終于在一位大佬的博客中得到解決,謝謝大哥!
https://blog.csdn.net/ambition_xiaoman/article/details/118609661
大家可以自行查看。

配置好的qt大概是這種的

能夠加載出地球即可

四、在QT環(huán)境中利用osgEarth3.2加載shp文件。

其中在QT環(huán)境配置好osgearth加載shp文件,網(wǎng)上有很多很多例子,但都是osgearth2.10的,但是osgearth2.1在qt上集成環(huán)境的例子好像沒(méi)有,查了很多很多教程和網(wǎng)站都沒(méi)有,我就根據(jù)osgEarth2.10的例子根據(jù)其幫助文檔進(jìn)行書(shū)寫(xiě)最終完成。

代碼如下(示例):

//頭文件 #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; // 計(jì)時(shí)器,每5ms觸發(fā)一次事件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();// 初始化設(shè)置osgvoid InitUI();//界面初始化void InitTimer();//屏幕刷新初始化void InitOsgearth();//初始化osgearthvoid InitSky();//天空初始化 private slots:// 定時(shí)更新幀的槽函數(shù)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()// 初始化設(shè)置osg {viewer = new osgViewer::Viewer;// 設(shè)置模型root = new osg::Group;// 顯示 .earth 文件中的地球模型//獲取屏幕分辨率 長(zhǎng)寬osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();if (!wsi)return;unsigned int width, height;wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);//設(shè)置圖形環(huán)境特性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;//創(chuàng)建圖形窗口是否使用雙緩存//設(shè)置照相機(jī)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);//設(shè)置渲染器viewer->setCamera(camera);viewer->setSceneData(root);viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);//創(chuàng)建為單線程viewer->addEventHandler(new osgGA::StateSetManipulator(viewer->getCamera()->getOrCreateStateSet())); } void osg32qt::InitOsgearth() {//earthNode = new osg::Node;//earthNode = osgDB::readNodeFile("./feature_labels.earth");//從底圖影像圖層開(kāi)始;我們將使用 GDAL 驅(qū)動(dòng)程序加載本地 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);//接下來(lái),我們添加一個(gè)圖層以提供要素?cái)?shù)據(jù)。osgEarth::OGRFeatureSource* features = new osgEarth::OGRFeatureSource();features->setURL("G:\\QT\\osgt\\osgearth-3.2\\data\\world.shp");//features->setURL()map->addLayer(features);//定義要素?cái)?shù)據(jù)的樣式。由于我們將渲染矢量作為線,配置線符號(hào)化器:osgEarth::Style style;//可見(jiàn)性osgEarth::RenderSymbol* rs = style.getOrCreate<osgEarth::RenderSymbol>();rs->depthTest() = false;//貼地設(shè)置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風(fēng)格加載到圖層中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());//優(yōu)化場(chǎng)景數(shù)據(jù)earthForm = new osg::MatrixTransform;//osgearth操作器 用來(lái)設(shè)置osgearhem = new osgEarth::Util::EarthManipulator;if (mapNode.valid()){em->setNode(mapNode);}em->getSettings()->setArcViewpointTransitions(true);//設(shè)置osg渲染窗口viewer->setCameraManipulator(em);//獲取地球半徑 設(shè)置視點(diǎn)//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() {//獲取當(dāng)前時(shí)間 初始化天空now_time = time(0);t_tm = localtime(&now_time);osgEarth::DateTime cur_date_time(now_time);osgEarth::Ephemeris* ephemeris = new osgEarth::Ephemeris;//設(shè)置黑夜明暗程度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);//添加到場(chǎng)景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("數(shù)字地球")); } 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

總結(jié)

OsgEarth3.2相關(guān)教程特別少,現(xiàn)在網(wǎng)絡(luò)上大多都是osgEarth2.10的版本,因?yàn)槲遗渲肙sgEarth2.10和qt的環(huán)境出了一些問(wèn)題,不然也不會(huì)用OsgEarth3.2了,繼續(xù)加油。

總結(jié)

以上是生活随笔為你收集整理的在Vs2017上集成osgearth3.2和qt5.9,并加载shp文件。的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。