当前位置: 首页 > news >正文

osgEarth之添加shp

目录

效果

代码

代码分析

加载模式


效果

代码

#include "stdafx.h"
#include <osg/Notify>
#include <osgGA/StateSetManipulator>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>#include <osgEarth/MapNode>
#include <osgEarth/ImageLayer>
#include <osgEarth/ModelLayer>
#include <osgEarthUtil/ExampleResources>
#include <osgEarthUtil/EarthManipulator>#include <osgEarthSymbology/Style>
#include <osgEarthFeatures/FeatureModelLayer>#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/feature_ogr/OGRFeatureOptions>
#include <osgEarthDrivers/agglite/AGGLiteOptions>using namespace osgEarth;
using namespace osgEarth::Features;
using namespace osgEarth::Drivers;
using namespace osgEarth::Symbology;
using namespace osgEarth::Util;int usage(const std::string& app)
{OE_NOTICE "\n" << app << "\n"	// 绘制特征的方法<< "  --rasterize           : draw features as rasterized image tiles \n" // 光栅化平铺瓦片图<< "  --drape               : draw features as projected texture \n"	// 投影纹理<< "  --clamp               : draw features using shader clamping \n"	// 使用贴地着色器<< "  --mem                 : load features from memory \n"				// 加载默认线<< "  --labels              : add feature labels \n"					// 添加文本标签<< "\n"<< MapNodeHelper().usage()<< std::endl;return 0;
}//
// NOTE: run this sample from the repo/tests directory.
//
int main(int argc, char** argv)
{osg::ArgumentParser arguments(&argc, argv);if (arguments.read("--help"))return usage(argv[0]);// cmd执行命令时,输入: osgearth_featuresd.exe --rasterize --mem --labels --drape --clamp (一些参数)// 当输入了某个参数,则获取到的值为1,否则为0/*bool useRaster = arguments.read("--rasterize");bool useMem = arguments.read("--mem");bool useLabels = arguments.read("--labels");bool useDraping = arguments.read("--drape");bool useClamping = arguments.read("--clamp");*/bool useRaster = true;bool useMem = true;bool useLabels = true;bool useDraping = true;bool useClamping = true;std::cout << useRaster << useMem << useLabels << useDraping << useClamping << std::endl;osgViewer::Viewer viewer(arguments);// Start by creating the map:Map* map = new Map();// Start with a basemap imagery layer; we'll be using the GDAL driver// to load a local GeoTIFF file:// 添加默认地图GDALOptions basemap;// GDAL选项类,继承自TileSourceOptionsbasemap.url() = "../data/world.tif";map->addLayer(new ImageLayer(ImageLayerOptions("basemap", basemap)));// Next we add a feature layer. // 添加shp文件OGRFeatureOptions featureData;if (!useMem){// Configures the feature driver to load the vectors from a shapefile:// 如果给出相对路径,则国界线总是加载不上// 此处必须给全路径!!!featureData.url() = "F:\\point-cloud-lab-new\\PointCloudLab\\GeoEngine_output\\data\\world.shp";std::cout << "add world.shp" << std::endl;}else{// the --mem options tells us to just make an in-memory geometry:// 当没有 --mem参数时,采用默认的line绘制Ring* line = new Ring();line->push_back(osg::Vec3d(60, 20, 0));line->push_back(osg::Vec3d(120, 20, 0));line->push_back(osg::Vec3d(120, 60, 0));line->push_back(osg::Vec3d(60, 60, 0));featureData.geometry() = line;std::cout << "don't add world.shp" << std::endl;}// Make a feature source layer and add it to the Map:// 制作特征源图层并添加到mapFeatureSourceLayerOptions ogrLayer;ogrLayer.name() = "vector-data";// 矢量数据ogrLayer.featureSource() = featureData;// shp 文件或者默认linemap->addLayer(new FeatureSourceLayer(ogrLayer));// Define a style for the feature data. Since we are going to render the// vectors as lines, configure the line symbolizer:// 设置矢量面样式(包括边界线)Style style;LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>();ls->stroke()->color() = Color::Yellow;ls->stroke()->width() = 2.0f;// 可以将线宽设置宽一些,更容易看出不同参数useDraping和useClamping产生的区别ls->tessellationSize()->set(100, Units::KILOMETERS);// 细分程度if (useDraping)//是否设置drape属性{AltitudeSymbol* alt = style.getOrCreate<AltitudeSymbol>();alt->clamping() = alt->CLAMP_TO_TERRAIN;alt->technique() = alt->TECHNIQUE_DRAPE;std::cout << "drape" << std::endl;}else if (useClamping)// 贴地属性{AltitudeSymbol* alt = style.getOrCreate<AltitudeSymbol>();alt->clamping() = alt->CLAMP_TO_TERRAIN;alt->technique() = alt->TECHNIQUE_GPU;// 线的细分程度ls->tessellationSize()->set(100, Units::KILOMETERS);RenderSymbol* render = style.getOrCreate<RenderSymbol>();render->depthOffset()->enabled() = true;render->depthTest() = false;std::cout << "no drape,but clamp" << std::endl;}if (useRaster)// 光栅化{AGGLiteOptions rasterOptions;rasterOptions.featureOptions() = featureData;rasterOptions.styles() = new StyleSheet();rasterOptions.styles()->addStyle(style);map->addLayer(new ImageLayer("My Features", rasterOptions));std::cout << "raster" << std::endl;}else //if (useGeom){FeatureModelLayerOptions fml;fml.name() = "My Features";fml.featureSourceLayer() = "vector-data";fml.styles() = new StyleSheet();fml.styles()->addStyle(style);// fml.enableLighting() = false;map->addLayer(new FeatureModelLayer(fml));std::cout << "no raster" << std::endl;}if (useLabels && !useRaster)// 有标签且非光栅化{// set up symbology for drawing labels. We're pulling the label// text from the name attribute, and its draw priority from the// population attribute.// 设置文本样式Style labelStyle;TextSymbol* text = labelStyle.getOrCreateSymbol<TextSymbol>();text->content() = StringExpression("[cntry_name]");//如果需要显示汉字,则需要转换成UTF-8编码text->priority() = NumericExpression("[pop_cntry]");text->size() = 26.0f;// 字号有些大text->alignment() = TextSymbol::ALIGN_CENTER_CENTER;text->fill()->color() = Color::White;text->halo()->color() = Color::DarkGray;// 文字光环颜色// and configure a model layer:FeatureModelLayerOptions fml;fml.name() = "Labels";fml.featureSourceLayer() = "vector-data";fml.styles() = new StyleSheet();fml.styles()->addStyle(labelStyle);map->addLayer(new FeatureModelLayer(fml));std::cout << "no raster, but labels" << std::endl;}// That's it, the map is ready; now create a MapNode to render the Map:MapNode* mapNode = new MapNode(map);viewer.setSceneData(mapNode);viewer.setCameraManipulator(new EarthManipulator());// add some stock OSG handlers:MapNodeHelper().configureView(&viewer);return viewer.run();
}

代码分析

osgEarth表达矢量的基本思路是:

  • 先将shp文件读取到矢量源图层FeatureSourceLayer中,
  • 这个图层加载到osgEarth的图层列表中是不显示的,
  • 必须得再加载一个专门的符号化图层,将其符号化,才能正常显示。

 
 
1. 先声明基础地图
osgEarth::Drivers::GDALOptions basemap;
basemap.url() = "world.tif";
// 添加影像图到map节点
map->addLayer( new ImageLayer(ImageLayerOptions("basemap", basemap)));
 
 
2. 加载特征数据
osgEarth::Drivers::OGRFeatureOptions featureData;
featureData.url() = "world.shp";
// 特征源图层选项设置
osgEarth::Features::FeatureSourceLayerOptions ogrLayer;
ogrLayer.name() = "vector-data";
ogrLayer.featureSource() = featureData;
map->addLayer(new osgEarth::Features::FeatureSourceLayer(ogrLayer));
 
/*******↑featureData添加到FeatureSourceLayer,*****↓符号化*******/
 
3.初始化线样式
// 对ls alt render 进行设置
Style style;
osgEarth::Symbology::LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>();
osgEarth::Symbology::AltitudeSymbol* alt = style.getOrCreate<AltitudeSymbol>();
osgEarth::Symbology::RenderSymbol* render = style.getOrCreate<RenderSymbol>();
 
 
4.光栅化或矢量化,二选一
4.1光栅化
osgEarth::Drivers::AGGLiteOptions rasterOptions;
rasterOptions.featureOptions() = featureData;
rasterOptions.styles()->addStyle( style );
map->addLayer(new ImageLayer("My Features", rasterOptions) );
 
4.2矢量化
osgEarth::Features::FeatureModelLayerOptions fml;
fml.styles()->addStyle(style);
map->addLayer(new FeatureModelLayer(fml));
 
5.如果需要加入label样式,以矢量化为前提
osgEarth::Symbology::Style labelStyle;
osgEarth::Symbology::TextSymbol* text = labelStyle.getOrCreateSymbol<TextSymbol>();
FeatureModelLayerOptions fml;
fml.styles()->addStyle( labelStyle );
map->addLayer(new FeatureModelLayer(fml));

加载模式

// rasterize 光栅化,不输入时,会显示名称
// mem参数输入,加载矩形,否则加载world.shp文件。shp文件路径一定要写全路径,否则无法加载。
// labels 可以不用填写。
// clamp 和 drape 任选其一。// 采用clamp方式绘制
osgearth_featuresd.exe --rasterize --mem --labels --clamp// 采用drape方式绘制
osgearth_featuresd.exe --rasterize --mem --labels --drape// 还有多种组合方式
osgearth_featuresd.exe --labels --drape

相关文章:

osgEarth之添加shp

目录 效果 代码 代码分析 加载模式 效果 代码 #include "stdafx.h" #include <osg/Notify> #include <osgGA/StateSetManipulator> #include <osgViewer/Viewer> #include <osgViewer/ViewerEventHandlers>#include <osgEarth/MapNo…...

Eolink Apikit 版本更新:「数据字典」功能上线、支持 MongoDB 数据库操作、金融行业私有化协议、GitLab 生成 API 文档...

&#x1f389; 新增 搭建自定义接口协议架构&#xff0c;支持快速适配金融行业各类型私有协议的导入、编辑和展示。 数据字典功能上线&#xff0c;支持以数据字典的形式管理参数枚举值&#xff1b; 数据库连接支持 MongoDB 数据库操作&#xff1b; 基于 Apikit 类型导入 API…...

GPT-4V:AI在医疗领域的应用

OpenAI最新发布的GPT-4V模型为ChatGPT增添了语音和图像功能&#xff0c;为用户提供了更多在日常生活中使用ChatGPT的方式。这次更新将为用户带来更加便捷、直观的交互体验&#xff0c;用户可以直接通过拍照上传图片&#xff0c;并提出相关问题。OpenAI的最终目标是构建一个安全…...

OpenCV 在ImShow窗体上选择感兴趣的区域

窗体上选择感兴趣ROI区域 在计算机视觉处理中, 通常是针对图像中的一个特定区域进行处理, 有时候这个特定区域需要人来选择, OpenCV 也提供了窗口选择ROI机制. 窗体支持两种选择ROI区域的方法, 一个是单选, 一个是多选, 操作方法如下: 单选: 通过鼠标在屏幕上选择区域, 然后通过…...

ubuntu 安装redis详细教程

下载redis安装包 链接如下&#xff1a; http://redis.io/download 本例版本为&#xff1a;redis-7.2.3.tar.gz 下载安装包到目录/opt下&#xff0c;路径可修改&#xff0c;本例为/opt wget https://github.com/redis/redis/archive/7.2.3.tar.gz 解压安装包&#xff0c;并…...

qframework 架构 (作者:凉鞋)使用笔记

一些准则&#xff1a; 根据VIEW->SYSTEM->MODEL的分层架构 初始架构&#xff1a; app. using FrameworkDesign;namespace ShootingEditor2D&#xff08;项目的命名空间&#xff09; {public class ShootingEditor2D &#xff08;游戏名称&#xff09;: Architecture&l…...

【JMeter】定时器分类以及场景介绍

1. 定时器分类 固定定时器 作用&#xff1a;请求之间设置等待时间应用场景&#xff1a;查询商品列表后&#xff0c;去查看列表商品详情页。针对商品列表数据量比较大的&#xff0c;响应时间会比较长&#xff0c;就需要设置等待时间然后去查看商详 2.定时器的作用域&#xff1…...

Spring Boot 请求/actuator/beans 无法访问 返回404

问题复现 在保证项目加入了spring-boot-starter-actuator依赖&#xff0c;并成功启动后。通过浏览器进行访问&#xff0c;返回如下图结果&#xff1a; 问题排查 1. 查看日志 从日志中可以看到基于路径’/actuator’下只暴露了一个端点 2. 访问http://localhost:8080/actua…...

AVD联网

AVD联网&#xff1a; 解决Android Studio模拟器无法联网_android studio模拟器没有网络-CSDN博客 挺好的&#xff0c;就是访问网站的时候只能用ip&#xff0c;而不能用域名。 AVD设置代理&#xff1a; android studio踩坑记 AVD模拟器代理设置_android studio avd 配置代理-…...

[Vue warn]: Missing required prop: “action“

控制台显示错误信息 vue.runtime.esm.js:4605 [Vue warn]: Missing required prop: "action" found in ---> <ElUpload> at packages/upload/src/index.vue <ElTableRow> <ElTableBody> <ElTable> at pack…...

Python标准库有哪些

概述 可用性注释 内置函数 内置常量 由 site 模块添加的常量 # Author : 小红牛 # 微信公众号&#xff1a;wdPython内置类型 逻辑值检测 布尔运算 — and, or, not 比较运算 数字类型 — int, float, complex 布尔类型 - bool 迭代器类型 序列类型 — list, tuple, range 文本…...

基于ssm的校园办公室报修管理系统

基于ssm的校园办公室报修管理系统 摘要 基于SSM的校园办公室报修管理系统是一个现代化的、高效的报修平台&#xff0c;它能够帮助校园内的教职工和学生更方便、更快捷地提交和处理报修请求。该系统基于Spring、SpringMVC和MyBatis&#xff08;简称SSM&#xff09;开发&#xff…...

1Panel 升级 Halo报错

1Panel 升级 Halo报错 通过 1panel 升级 2.10.0 -> 2.10.1 后启动失败,出现 No value found for protocol 错误&#xff0c; 1Panel-halo-rzxY | Caused by: io.r2dbc.spi.NoSuchOptionException: No value found for protocol 1Panel-halo-rzxY | at io.r2dbc.spi.Conn…...

spring-clound基础开发

一、使用openfeig调用远程另外一个服务接口 1、创建一个spring boot工程,并且创建2个模块来当微服务模块 2、分别配置2个模块的启动文件 3、分别两个模块下创建一个测试的控制器 4、在项目的根目录的pom.xml中添加spring-cloud配置 <properties><java.version>1…...

基于SSM的劳务外包管理系统的设计与实现

末尾获取源码 开发语言&#xff1a;Java Java开发工具&#xff1a;JDK1.8 后端框架&#xff1a;SSM 前端&#xff1a;Vue 数据库&#xff1a;MySQL5.7和Navicat管理工具结合 服务器&#xff1a;Tomcat8.5 开发软件&#xff1a;IDEA / Eclipse 是否Maven项目&#xff1a;是 目录…...

uni-app学习笔记(二)

目录 一、路由与页面跳转 1、tabar与普通页面跳转例子 2、navigateTo 3、switchTab 二、vue组件 1、传统vue组件的使用 2、easycom 三、uView组件库 1、安装配置 2、引入配置 3、使用 四、Vuex 1、认识 2、state基本使用 3、mapState使用 五、网络请求 1、封装…...

使用axios拦截器解决前端并发冲突问题

使用 axios 拦截器解决「 前端并发冲突 」 问题 背景 并发冲突问题&#xff0c; 是日常开发中一个比较常见的问题。 不同用户在较短时间间隔内变更数据&#xff0c;或者某一个用户进行的重复提交操作都可能导致并发冲突。 并发场景在开发和测试阶段难以排查全面&#xff0c…...

IPv6详解

目录: 第一部分 IPv6的诞生背景和引起的主要变化 第二部分 IPv6数据报的基本首部和扩展首部 第三部分 IPv6地址 第四部分 IPv4向IPv6过渡 第一部分 IPv6的诞生背景和引起的主要变化 一.IPv6的诞生背景 IPv4存在设计缺陷: IPv4的设计者最初并没有想到该协议会在全球范围内广…...

【C++干货铺】STL简述 | string类的使用指南

个人主页点击直达&#xff1a;小白不是程序媛 C系列专栏&#xff1a;C干货铺 代码仓库&#xff1a;Gitee 目录 什么是STL STL的版本 STL的六大组件 STL的缺陷 string类 C语言中的字符串 标准库中的string类 string类常用的接口使用指南 string类中常见的构造 strin…...

合肥工业大学数字逻辑实验三

** 数字逻辑 实验报告** ✅作者简介:CSDN内容合伙人、信息安全专业在校大学生🏆 🔥系列专栏 :hfut实验课设 📃新人博主 :欢迎点赞收藏关注,会回访! 💬舞台再大,你不上台,永远是个观众。平台再好,你不参与,永远是局外人。能力再大,你不行动,只能看别人成功!…...

智能在线客服平台:数字化时代企业连接用户的 AI 中枢

随着互联网技术的飞速发展&#xff0c;消费者期望能够随时随地与企业进行交流。在线客服平台作为连接企业与客户的重要桥梁&#xff0c;不仅优化了客户体验&#xff0c;还提升了企业的服务效率和市场竞争力。本文将探讨在线客服平台的重要性、技术进展、实际应用&#xff0c;并…...

(二)原型模式

原型的功能是将一个已经存在的对象作为源目标,其余对象都是通过这个源目标创建。发挥复制的作用就是原型模式的核心思想。 一、源型模式的定义 原型模式是指第二次创建对象可以通过复制已经存在的原型对象来实现,忽略对象创建过程中的其它细节。 📌 核心特点: 避免重复初…...

网络编程(UDP编程)

思维导图 UDP基础编程&#xff08;单播&#xff09; 1.流程图 服务器&#xff1a;短信的接收方 创建套接字 (socket)-----------------------------------------》有手机指定网络信息-----------------------------------------------》有号码绑定套接字 (bind)--------------…...

C++八股 —— 单例模式

文章目录 1. 基本概念2. 设计要点3. 实现方式4. 详解懒汉模式 1. 基本概念 线程安全&#xff08;Thread Safety&#xff09; 线程安全是指在多线程环境下&#xff0c;某个函数、类或代码片段能够被多个线程同时调用时&#xff0c;仍能保证数据的一致性和逻辑的正确性&#xf…...

selenium学习实战【Python爬虫】

selenium学习实战【Python爬虫】 文章目录 selenium学习实战【Python爬虫】一、声明二、学习目标三、安装依赖3.1 安装selenium库3.2 安装浏览器驱动3.2.1 查看Edge版本3.2.2 驱动安装 四、代码讲解4.1 配置浏览器4.2 加载更多4.3 寻找内容4.4 完整代码 五、报告文件爬取5.1 提…...

深度学习水论文:mamba+图像增强

&#x1f9c0;当前视觉领域对高效长序列建模需求激增&#xff0c;对Mamba图像增强这方向的研究自然也逐渐火热。原因在于其高效长程建模&#xff0c;以及动态计算优势&#xff0c;在图像质量提升和细节恢复方面有难以替代的作用。 &#x1f9c0;因此短时间内&#xff0c;就有不…...

Redis:现代应用开发的高效内存数据存储利器

一、Redis的起源与发展 Redis最初由意大利程序员Salvatore Sanfilippo在2009年开发&#xff0c;其初衷是为了满足他自己的一个项目需求&#xff0c;即需要一个高性能的键值存储系统来解决传统数据库在高并发场景下的性能瓶颈。随着项目的开源&#xff0c;Redis凭借其简单易用、…...

免费数学几何作图web平台

光锐软件免费数学工具&#xff0c;maths,数学制图&#xff0c;数学作图&#xff0c;几何作图&#xff0c;几何&#xff0c;AR开发,AR教育,增强现实,软件公司,XR,MR,VR,虚拟仿真,虚拟现实,混合现实,教育科技产品,职业模拟培训,高保真VR场景,结构互动课件,元宇宙http://xaglare.c…...

解读《网络安全法》最新修订,把握网络安全新趋势

《网络安全法》自2017年施行以来&#xff0c;在维护网络空间安全方面发挥了重要作用。但随着网络环境的日益复杂&#xff0c;网络攻击、数据泄露等事件频发&#xff0c;现行法律已难以完全适应新的风险挑战。 2025年3月28日&#xff0c;国家网信办会同相关部门起草了《网络安全…...

解析奥地利 XARION激光超声检测系统:无膜光学麦克风 + 无耦合剂的技术协同优势及多元应用

在工业制造领域&#xff0c;无损检测&#xff08;NDT)的精度与效率直接影响产品质量与生产安全。奥地利 XARION开发的激光超声精密检测系统&#xff0c;以非接触式光学麦克风技术为核心&#xff0c;打破传统检测瓶颈&#xff0c;为半导体、航空航天、汽车制造等行业提供了高灵敏…...