OsgEarth —— 笔记9 - 飞机加入跟踪半透明圆圈标识(附源码)

这篇博客介绍了如何在OsgEarth中为飞机添加跟随的半透明圆圈标识,提供源码供读者参考学习。文章是OsgEarth系列笔记的一部分,包括了从创建地球到飞机飞行、轨迹显示等多个步骤。
### 环境准备 确保已安装好osgEarth和PostgreSQL数据库,并且PostgreSQL中存储有矢量数据。同时要保证osgEarth编译时开启了对PostgreSQL的支持。 ### 配置文件编写 osgEarth通常使用配置文件(.earth文件)来加载数据。以下是一个简单的示例,展示如何在.earth文件中配置加载PostgreSQL数据库中的矢量数据: ```xml <map name="PostgreSQL Vector Data" type="geocentric"> <options> <cache type="filesystem" path="cache"/> </options> <layers> <featurelayer name="PostgreSQL Vector Layer"> <driver name="postgis"> <db connection="host=localhost dbname=your_database user=your_user password=your_password"/> <table name="your_table" primary_key="id" geometry_column="geom"/> <feature_profile> <srs>wkt:EPSG:4326</srs> </feature_profile> </driver> <style> <rule> <symbolizer class="polygon"> <fill color="#FF0000" alpha="0.5"/> <stroke color="#000000" width="1"/> </symbolizer> </rule> </style> </featurelayer> </layers> </map> ``` 在上述配置文件中: - `<db connection>`:指定连接到PostgreSQL数据库的信息,包括主机名、数据库名、用户名和密码。 - `<table>`:指定要查询的表名、主键列和几何列名。 - `<feature_profile>`:指定数据的空间参考系统。 - `<style>`:定义了矢量数据的显示样式,这里设置了多边形的填充颜色和边框样式。 ### 代码加载 以下是一个简单的C++代码示例,用于加载上述配置文件并显示数据: ```cpp #include <osgViewer/Viewer> #include <osgEarth/MapNode> #include <osgEarthUtil/EarthManipulator> int main() { osgViewer::Viewer viewer; osg::ref_ptr<osgEarth::Map> map = osgEarth::Map::create(); osg::ref_ptr<osgEarth::MapNode> mapNode = new osgEarth::MapNode(map); // 加载.earth文件 osg::ref_ptr<osg::Node> earthNode = osgDB::readRefFile("your_config.earth"); if (earthNode.valid()) { mapNode->setMap(earthNode->asGroup()->getChild(0)->as<osgEarth::MapNode>()->getMap()); } viewer.setSceneData(mapNode); viewer.setCameraManipulator(new osgEarthUtil::EarthManipulator()); return viewer.run(); } ``` ### 注意事项 - 确保数据库连接信息正确,包括主机名、数据库名、用户名和密码。 - 确认表名、主键列和几何列名与数据库中的实际情况一致。 - 若数据的空间参考系统与配置文件中指定的不一致,可能会导致数据显示位置错误,需要进行坐标转换。 ### 错误排查 - 如果无法连接到数据库,检查数据库服务是否正常运行,以及连接信息是否正确。 - 若数据未显示,检查表名、列名和空间参考系统是否正确,也可以查看osgEarth的日志信息来定位问题。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

信必诺

嗨,支持下哥们呗。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值