当前位置: 首页 > 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实验课设 📃新人博主 :欢迎点赞收藏关注,会回访! 💬舞台再大,你不上台,永远是个观众。平台再好,你不参与,永远是局外人。能力再大,你不行动,只能看别人成功!…...

uniapp 对接腾讯云IM群组成员管理(增删改查)

UniApp 实战&#xff1a;腾讯云IM群组成员管理&#xff08;增删改查&#xff09; 一、前言 在社交类App开发中&#xff0c;群组成员管理是核心功能之一。本文将基于UniApp框架&#xff0c;结合腾讯云IM SDK&#xff0c;详细讲解如何实现群组成员的增删改查全流程。 权限校验…...

vscode里如何用git

打开vs终端执行如下&#xff1a; 1 初始化 Git 仓库&#xff08;如果尚未初始化&#xff09; git init 2 添加文件到 Git 仓库 git add . 3 使用 git commit 命令来提交你的更改。确保在提交时加上一个有用的消息。 git commit -m "备注信息" 4 …...

超短脉冲激光自聚焦效应

前言与目录 强激光引起自聚焦效应机理 超短脉冲激光在脆性材料内部加工时引起的自聚焦效应&#xff0c;这是一种非线性光学现象&#xff0c;主要涉及光学克尔效应和材料的非线性光学特性。 自聚焦效应可以产生局部的强光场&#xff0c;对材料产生非线性响应&#xff0c;可能…...

基于距离变化能量开销动态调整的WSN低功耗拓扑控制开销算法matlab仿真

目录 1.程序功能描述 2.测试软件版本以及运行结果展示 3.核心程序 4.算法仿真参数 5.算法理论概述 6.参考文献 7.完整程序 1.程序功能描述 通过动态调整节点通信的能量开销&#xff0c;平衡网络负载&#xff0c;延长WSN生命周期。具体通过建立基于距离的能量消耗模型&am…...

【Linux】C语言执行shell指令

在C语言中执行Shell指令 在C语言中&#xff0c;有几种方法可以执行Shell指令&#xff1a; 1. 使用system()函数 这是最简单的方法&#xff0c;包含在stdlib.h头文件中&#xff1a; #include <stdlib.h>int main() {system("ls -l"); // 执行ls -l命令retu…...

使用van-uploader 的UI组件,结合vue2如何实现图片上传组件的封装

以下是基于 vant-ui&#xff08;适配 Vue2 版本 &#xff09;实现截图中照片上传预览、删除功能&#xff0c;并封装成可复用组件的完整代码&#xff0c;包含样式和逻辑实现&#xff0c;可直接在 Vue2 项目中使用&#xff1a; 1. 封装的图片上传组件 ImageUploader.vue <te…...

UR 协作机器人「三剑客」:精密轻量担当(UR7e)、全能协作主力(UR12e)、重型任务专家(UR15)

UR协作机器人正以其卓越性能在现代制造业自动化中扮演重要角色。UR7e、UR12e和UR15通过创新技术和精准设计满足了不同行业的多样化需求。其中&#xff0c;UR15以其速度、精度及人工智能准备能力成为自动化领域的重要突破。UR7e和UR12e则在负载规格和市场定位上不断优化&#xf…...

今日学习:Spring线程池|并发修改异常|链路丢失|登录续期|VIP过期策略|数值类缓存

文章目录 优雅版线程池ThreadPoolTaskExecutor和ThreadPoolTaskExecutor的装饰器并发修改异常并发修改异常简介实现机制设计原因及意义 使用线程池造成的链路丢失问题线程池导致的链路丢失问题发生原因 常见解决方法更好的解决方法设计精妙之处 登录续期登录续期常见实现方式特…...

JS设计模式(4):观察者模式

JS设计模式(4):观察者模式 一、引入 在开发中&#xff0c;我们经常会遇到这样的场景&#xff1a;一个对象的状态变化需要自动通知其他对象&#xff0c;比如&#xff1a; 电商平台中&#xff0c;商品库存变化时需要通知所有订阅该商品的用户&#xff1b;新闻网站中&#xff0…...

MySQL 部分重点知识篇

一、数据库对象 1. 主键 定义 &#xff1a;主键是用于唯一标识表中每一行记录的字段或字段组合。它具有唯一性和非空性特点。 作用 &#xff1a;确保数据的完整性&#xff0c;便于数据的查询和管理。 示例 &#xff1a;在学生信息表中&#xff0c;学号可以作为主键&#xff…...