加载osgearth自带的world.shp矢量数据:

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;#include <osgViewer/Viewer>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Group>
#include <osg/Switch>
#include <osg/Billboard>
#include <osg/Texture2D>
#include <osg/Image>
#include <osg/Vec3>
#include <osg/Vec2>
#include <osg/PositionAttitudeTransform>
#include <osg/MatrixTransform>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>
#include <osg/PagedLOD>
#include <osgSim/Impostor>
#include <osgViewer/ViewerEventHandlers> //事件监听
#include <osgGA/StateSetManipulator> //事件响应类,对渲染状态进行控制
#include <osgUtil/Simplifier> //简化几何体#include <osgEarth/MapNode>
#include <osgEarth/ImageLayer>
#include <osgEarth/GLUtils>#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/cache_filesystem/FileSystemCache>
#include <osgEarthDrivers/feature_ogr/OGRFeatureOptions>#include <osgEarthFeatures/FeatureSourceLayer>
#include <osgEarthFeatures/FeatureModelLayer>
#include <osgEarthUtil/EarthManipulator>#pragma comment(lib, "OpenThreadsd.lib")
#pragma comment(lib, "osgd.lib")
#pragma comment(lib, "osgDBd.lib")
#pragma comment(lib, "osgUtild.lib")
#pragma comment(lib, "osgGAd.lib")
#pragma comment(lib, "osgViewerd.lib")
#pragma comment(lib, "osgTextd.lib")
#pragma comment(lib, "osgSimd.lib")#pragma comment(lib, "osgEarthd.lib")
#pragma comment(lib, "osgEarthFeaturesd.lib")
#pragma comment(lib, "osgEarthUtild.lib")
#pragma comment(lib, "osgEarthSymbologyd.lib")void AddAnno(std::string filePath, osg::ref_ptr<osgEarth::Map> map)
{osgEarth::Symbology::Style labelStyle;osgEarth::Symbology::TextSymbol* text = labelStyle.getOrCreateSymbol<osgEarth::Symbology::TextSymbol>();string name = "[CNTRY_NAME]";      //如果需要显示汉字,则需要转换成UTF-8编码text->content() = osgEarth::Symbology::StringExpression(name);text->priority() = osgEarth::NumericExpression("[pop_cntry]");text->size() = 16.0f;text->alignment() = osgEarth::Symbology::TextSymbol::ALIGN_CENTER_CENTER;text->fill()->color() = osgEarth::Symbology::Color::White;text->halo()->color() = osgEarth::Symbology::Color::Red;text->encoding() = osgEarth::Symbology::TextSymbol::ENCODING_UTF8;//string fontFile = PathRef::GetAppDir() + "/fonts/SourceHanSansCN-Regular.ttf";//text->font() = fontFile;         //如果显示汉字,需要支持中文字库的字体// and configure a model layer:osgEarth::Features::FeatureModelLayerOptions fmlOpt;fmlOpt.name() = filePath + "_labels";fmlOpt.featureSourceLayer() = filePath + "_source";fmlOpt.styles() = new osgEarth::Symbology::StyleSheet();fmlOpt.styles()->addStyle(labelStyle);osg::ref_ptr<osgEarth::Features::FeatureModelLayer> fml = new osgEarth::Features::FeatureModelLayer(fmlOpt);map->addLayer(fml);
}void AddVector(osg::ref_ptr<osgEarth::Map> map)
{//std::string filePath = "E:/OSGCore/data/world.shp";osgEarth::Drivers::OGRFeatureOptions featureData;featureData.url() = filePath;//     如果缺少空间参考,可以手动指定   //    ifstream infile("C:/Data/vector/hs/23.prj");//    string line;//    getline(infile, line);//    featureData.profile()->srsString() = line;// Make a feature source layer and add it to the Map:osgEarth::Features::FeatureSourceLayerOptions ogrLayer;ogrLayer.name() = filePath + "_source";ogrLayer.featureSource() = featureData;osgEarth::Features::FeatureSourceLayer*  featureSourceLayer = new osgEarth::Features::FeatureSourceLayer(ogrLayer);map->addLayer(featureSourceLayer);osgEarth::Features::FeatureSource *features = featureSourceLayer->getFeatureSource();if (!features){printf(("无法打开该矢量文件!"));return;}//设置样式osgEarth::Symbology::Style style;//可见性osgEarth::Symbology::RenderSymbol* rs = style.getOrCreate<osgEarth::Symbology::RenderSymbol>();rs->depthTest() = false;//贴地设置osgEarth::Symbology::AltitudeSymbol* alt = style.getOrCreate<osgEarth::Symbology::AltitudeSymbol>();alt->clamping() = alt->CLAMP_TO_TERRAIN;alt->technique() = alt->TECHNIQUE_DRAPE;//设置矢量面样式(包括边界线)osgEarth::Symbology::LineSymbol* ls = style.getOrCreateSymbol<osgEarth::Symbology::LineSymbol>();ls->stroke()->color() = osgEarth::Symbology::Color("#FA8072");ls->stroke()->width() = 1.0;ls->tessellationSize()->set(100, osgEarth::Units::KILOMETERS);osgEarth::Symbology::PolygonSymbol *polygonSymbol = style.getOrCreateSymbol<osgEarth::Symbology::PolygonSymbol>();polygonSymbol->fill()->color() = osgEarth::Symbology::Color(152.0f / 255, 251.0f / 255, 152.0f / 255, 0.8f); //238 230 133polygonSymbol->outline() = true;//osgEarth::Features::FeatureModelLayerOptions fmlOpt;fmlOpt.name() = filePath;fmlOpt.featureSourceLayer() = filePath + "_source";fmlOpt.enableLighting() = false;fmlOpt.styles() = new osgEarth::Symbology::StyleSheet();fmlOpt.styles()->addStyle(style);osg::ref_ptr<osgEarth::Features::FeatureModelLayer> fml = new osgEarth::Features::FeatureModelLayer(fmlOpt);map->addLayer(fml);AddAnno(filePath, map);
}int main()
{osgEarth::ProfileOptions profileOpts;//地图配置:设置缓存目录osgEarth::Drivers::FileSystemCacheOptions cacheOpts;string cacheDir = "E:/OSGCore/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() = "E:/OSGCore/data/world.tif";osg::ref_ptr<osgEarth::ImageLayer> layer = new osgEarth::ImageLayer("BlueMarble", gdal);map->addLayer(layer);AddVector(map);osgViewer::Viewer viewer;viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));viewer.addEventHandler(new osgViewer::StatsHandler());//实现状态信息统计viewer.addEventHandler(new osgViewer::WindowSizeHandler());viewer.setSceneData(mapNode);osg::ref_ptr< osgEarth::Util::EarthManipulator> mainManipulator = new osgEarth::Util::EarthManipulator;viewer.setCameraManipulator(mainManipulator);//解决Lines or Annotations (FeatureNode, etc.) 不被渲染的问题osgEarth::GLUtils::setGlobalDefaults(viewer.getCamera()->getOrCreateStateSet());viewer.setUpViewInWindow(100, 100, 800, 600);return viewer.run();
}

osgEarth 加载矢量shp数据相关推荐

  1. osgearth加载本地离线影像瓦片地图

    osgearth加载本地离线影像瓦片地图案例 说明 本实例演示重新编译bing驱动直接加载本地离线影像瓦片地图. 本实例使用软件版本:osg3.3.1和osgEarth2.5 VC10编译环境(参考o ...

  2. 在奥维中如何加载星图地球数据云的地图?

    图源多.数据时效性高.数据精度高等方面的优势,使得星图地球数据云已经成为了国产在线地图的优秀选手. 对于从事数字地球相关开发的小伙伴们来说,如何成功调用在线地图才是真正关心的问题.本篇就简单讲解下奥维 ...

  3. osgEarth加载谷歌卫星地图的源码案例

    一.准备工作 安装水经注万能地图下载器,如果没有安装本软件,可以百度" 水经注软件 "到官方网站下载. 编译OSG.OSGEarth和第三方插件等,这里有一个已经编译好的vs201 ...

  4. OsgEarth加载DEM高程切片

    DEM数据下载 登录地理空间数据云,导航到高级检索,选择数据集(SRTMDEM 90M 分辨率原始高程数据),并设置好行政区进行检索. DEM数据拼接 下载的SRTM数据为分块的*.img栅格数据,使 ...

  5. 使用Vant框架的组件van-pull-refresh搭配van-list和van-card完成上滑加载更多列表数据,下拉刷新当前列表数据(等同于翻页功能)

    <template><div class="sg-page-body"><div class="sg-list"><v ...

  6. R语言广义加性模型(GAMs:Generalized Additive Model)建模:数据加载、划分数据、并分别构建线性回归模型和广义线性加性模型GAMs、并比较线性模型和GAMs模型的性能

    R语言广义加性模型(GAMs:Generalized Additive Model)建模:数据加载.划分数据.并分别构建线性回归模型和广义线性加性模型GAMs.并比较线性模型和GAMs模型的性能 目录

  7. bootstraptable 加载完成_bootstrap table onLoadSuccess加载服务端数据成功事件

    bootstrap table onLoadSuccess加载服务端数据成功事件 bootstrap table onLoadSuccess加载服务端数据成功的事件,该事件的作用是什么呢?服务端返回自 ...

  8. Qt Creator加载占位符数据

    Qt Creator加载占位符数据 加载占位符数据 使用虚拟模型 创建虚拟上下文 加载占位符数据 设计模式支持视图,模型和委托,因此,当您添加网格视图,列表视图或路径视图项时,将自动添加ListMod ...

  9. mvvm 耗时加载进度条_ZK的实际应用:MVVM –加载和渲染数据

    mvvm 耗时加载进度条 先前的文章简要介绍了RIA框架ZK,以及其CSS Selector启发的控制器机制如何通过使在控制器类中引用UI组件的任务变得相对灵活来减轻UI更改所带来的一些负担. 然后, ...

  10. ZK的实际应用:MVVM –加载和渲染数据

    先前的文章简要介绍了RIA框架ZK,以及它CSS Selector启发式控制器机制如何通过使在控制器类中引用UI组件的任务变得相对灵活来减轻UI更改所带来的一些负担. 然后,我们在上一篇文章中探讨了Z ...

最新文章

  1. 配置mysql主从服务器
  2. 英特尔详解5G将如何助力VR的未来发展
  3. MySQL子查询优化思路
  4. 碧雪情天服务器地址源如何修改,今天维护吗,碧雪情天怎么进不去啊,知道的说一下...
  5. Objective-C 语法
  6. esrgan_ESRGAN: Enhanced Super-Resolution Generative Adversarial Networks【阅读笔记】
  7. 从应届技术男到百度VP,这是低调到没百科的吴海锋首次受访
  8. Jmeter4.0---- HTTP请求默认值(14)
  9. php sql注入教程,PHP简单高效防御sql注入的方法分享
  10. PyQt5快速入门教程4-QtDesigner设计登录界面
  11. 应用添加分享至微信、QQ和微博
  12. Soul App 后台Api接口
  13. python俄罗斯方块思路_python实现俄罗斯方块小游戏
  14. PHP的strtolower()和strtoupper()函数在安装非中文系统的服务器下可能会将汉字转换为乱码
  15. Android 关于所谓的 深度睡眠 的问题
  16. cesium面积测量
  17. HTML5面试题总结
  18. easyPOI和导入复杂excel的各种坑
  19. 为什么cleancode
  20. android模拟登陆,Android模拟登录V2EX

热门文章

  1. 简单利用字典破解zip文件口令
  2. SQL分页查询,SQL的LIMIT语句用法,SQL如何实现分页查询,SpringBoot实现分页查询。
  3. 高性能实现WORD转PDF(jacob1.19+SaveAsPDFandXPS)内附资源链接
  4. VS用c#创建记事本
  5. 一个成功的网络营销案例的分析
  6. SQL Serevr 2012 安装教程
  7. BT种子 磁力链接 是什么?
  8. 图书管理系统(借还图书)--Java实现(附源码)
  9. 高数篇(二)-- 傅里叶变换 VS 拉普拉斯变换
  10. PRML学习总结(1)——Introduction