OsgEarth加载shp文件问题以及shp文件介绍
加载环境:
osgEarth3.2+VS2019+QT5.12
osgEarth加载shp文件相关代码参考链接:
在Vs2017上集成osgearth3.2和qt5.9,并加载shp文件
void QtGuiTest::InitOsgEarth()
{//earthNode = new osg::Node;//earthNode = osgDB::readNodeFile("feature_border.earth");//从底图影像图层开始;我们将使用 GDAL 驱动程序加载本地 GeoTIFF 文件:map = new osgEarth::Map();osgEarth::GDALImageLayer* basemap = new osgEarth::GDALImageLayer();basemap->setURL("D:\\VisualStudioProjects\\QtGuiTest\\world1.tif");map->addLayer(basemap);//接下来,我们添加一个图层以提供要素数据。osgEarth::OGRFeatureSource* features = new osgEarth::OGRFeatureSource();features->setURL("D:/OsgEarth3.2/data/world.shp");//features->setURL()map->addLayer(features);//定义要素数据的样式。由于我们将渲染矢量作为线,配置线符号化器:osgEarth::Style style;//可见性osgEarth::RenderSymbol* rs = style.getOrCreate<osgEarth::RenderSymbol>();rs->depthTest() = false;//贴地设置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::FeatureImageLayer* layer = new osgEarth::FeatureImageLayer();layer->setFeatureSource(features);//将style风格加载到图层中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 = new osgEarth::MapNode();//mapnode初始化//mapNode = osgEarth::MapNode::findMapNode(earthNode.get());//优化场景数据earthForm = new osg::MatrixTransform;//osgearth操作器 用来设置osgearhem = new osgEarth::Util::EarthManipulator;if (mapNode.valid()){em->setNode(mapNode);}//em->setNode(earthNode);em->getSettings()->setArcViewpointTransitions(true);//设置osg渲染窗口viewer->setCameraManipulator(em);osgEarth::GLUtils::setGlobalDefaults(viewer->getCamera()->getOrCreateStateSet());//获取地球半径 设置视点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, 1.0 * earth_R), 5);//初始化天空InitSky();
}
可以看到,shp文件world.shp并没有显示出来。
代码没有问题,为什么人家都可以显示,而自己运行的时候没有显示?最后终于找到了问题。
所谓的shp文件也称Shapefile文件,指的是一种文件存储的方法,实际上该种文件格式是由多个文件组成的。其中,要组成一个Shapefile,有三个文件是必不可少的,它们分别是".shp", ".shx"与 ".dbf"文件。表示同一数据的一组文件其文件名前缀应该相同。
所以,如果在目录中只有一个.shp文件,是不可能成功加载的。而我恰恰就是因为这个原因。
把shp文件补全,如下图所示:
再次运行,OK
OsgEarth加载shp文件问题以及shp文件介绍相关推荐
- osgearth处理大tiff文件:利用VPB工具构建静态四叉树,使用osgearth加载成为地形层
1.使用VPB工具处理tif osgdem -t image.tif --wkt-file wkt.prj -l 20 --PagedLOD -o tj_out.ive 2.osgearth加载ear ...
- osgearth加载本地离线影像瓦片地图
osgearth加载本地离线影像瓦片地图案例 说明 本实例演示重新编译bing驱动直接加载本地离线影像瓦片地图. 本实例使用软件版本:osg3.3.1和osgEarth2.5 VC10编译环境(参考o ...
- osgEarth加载谷歌卫星地图的源码案例
一.准备工作 安装水经注万能地图下载器,如果没有安装本软件,可以百度" 水经注软件 "到官方网站下载. 编译OSG.OSGEarth和第三方插件等,这里有一个已经编译好的vs201 ...
- OsgEarth加载DEM高程切片
DEM数据下载 登录地理空间数据云,导航到高级检索,选择数据集(SRTMDEM 90M 分辨率原始高程数据),并设置好行政区进行检索. DEM数据拼接 下载的SRTM数据为分块的*.img栅格数据,使 ...
- opengl加载显示3D模型UC类型文件
opengl加载显示3D模型UC类型文件 前置条件 注意事项 项目展示 项目完整C++源代码 前置条件 opengl三方库freeglut,显示uc格式的三维模型文件, 注意事项 源代码 model_ ...
- opengl加载显示3D模型3d类型文件
opengl加载显示3d模型UC类型文件 前置条件 注意事项 项目展示 项目完整C++源代码 前置条件 opengl三方库freeglut,显示3d格式的三维模型文件, 注意事项 源代码 model_ ...
- opengl加载显示3DS模型3DS类型文件
opengl加载显示3DS模型UC类型文件 前置条件 注意事项 项目展示 项目完整C++源代码 前置条件 opengl三方库freeglut,显示3DS格式的三维模型文件 注意事项 源代码 model ...
- opengl加载显示3D模型3MF类型文件
opengl加载显示3D模型3MF类型文件 前置条件 注意事项 项目展示 项目完整C++源代码 前置条件 opengl三方库freeglut,显示3MF格式的三维模型文件 注意事项 源代码 model ...
- opengl加载显示3D模型AC类型文件
opengl加载显示3D模型AC类型文件 前置条件 注意事项 项目展示 项目完整C++源代码 前置条件 opengl三方库freeglut,显示AC格式的三维模型文件 注意事项 源代码 model_f ...
- opengl加载显示3D模型AMF类型文件
opengl加载显示3D模型AMF类型文件 前置条件 注意事项 项目展示 项目完整C++源代码 前置条件 opengl三方库freeglut,显示AMF格式的三维模型文件 注意事项 源代码 model ...
最新文章
- JS代码报错 Uncaught SyntaxError: Unexpected token ,
- 三、神兽变变变(下)
- LeetCode Super Ugly Number
- logging 模块
- 计算bom的准确用量
- 使用LightBDD轻松实现行为驱动开发
- PWA(Progressive Web App)入门系列:Push
- 经典面试题(31):以下代码将输出的结果是什么?
- 信息安全工程师考试大纲-科目2:信息安全应用技术
- java做网页客户端_如何成为 Java web开发者
- 记录几个Maven库地址
- Appimage版wine乱码解决
- 某些函数原型及其用法
- Bitmap图片去除白色背景
- CCF计算机职业资格认证数字排序问题
- 动手学强化学习(一):多臂老虎机 Multi-armed Bandit
- 嵌入式了解 以及学习路线
- 2014 年最热门的国人开发开源软件 TOP 100 - 开源中国社区
- el-table 表格展开与折叠
- 数据结构实验二:7-2 两个有序链表序列的合并