OSGEARTH3 加载一个地球 您所在的位置:网站首页 earth元地球 OSGEARTH3 加载一个地球

OSGEARTH3 加载一个地球

2024-01-22 23:22| 来源: 网络整理| 查看: 265

OSGEARTH3 加载一个地球 方法一: 读取*.earth文件方法二: 图层加载 在这里插入图片描述

方法一: 读取*.earth文件

读取*.earth文件加载,改文件格式是xml形式,每个节点代表指定的图层:

FreeEarth_flat_simple.earth文件内容,加载一个基础图层,即使用一张全球大图作为底图: world.tif的路径是相对于*.earth文件的。 ../world.tif OGRRegisterAll(); GDALAllRegister(); CPLSetConfigOption("GDAL_DATA", "../../Data/gdal_data"); CPLSetConfigOption("CPL_DEBUG", "YES"); CPLSetConfigOption("CPL_LOG", "../LOG/gdal.log"); osgEarth::initialize(); { // map osg::Node* globe = osgDB::readNodeFile("../../Data/3d-data/Data/earth/FreeEarth_flat_simple.earth"); osgEarth::MapNode* mapNode = osgEarth::MapNode::get(globe); // viewer osgViewer::Viewer viewer; viewer.setSceneData(mapNode); // manipulator osg::ref_ptr mainManipulator = new osgEarth::Util::EarthManipulator; viewer.setCameraManipulator(mainManipulator); // run viewer.setUpViewInWindow(100, 100, 800, 600); viewer.run(); } return 0; } 方法二: 图层加载

直接通过代码的形式创建layer, 进行加载:. world.tif路径相对于exe. 1. 初始化GDAL; 2. 初始化OSGEARTH; 3. 加载地球. 4. 加载基础图层 5. 运行

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char** argv) { OGRRegisterAll(); GDALAllRegister(); CPLSetConfigOption("GDAL_DATA", "../../Data/gdal_data"); CPLSetConfigOption("CPL_DEBUG", "YES"); CPLSetConfigOption("CPL_LOG", "../LOG/gdal.log"); osgEarth::initialize(); { // map(empty) osg::ref_ptr map = new osgEarth::Map; osg::ref_ptr mapNode = new osgEarth::MapNode(map); // base layer osg::ref_ptr baselayer = new osgEarth::GDALImageLayer(); baselayer->setURL("../../Data/3d-data/Data/world.tif"); map->addLayer(baselayer); // viewer osgViewer::Viewer viewer; viewer.setSceneData(mapNode); osg::ref_ptr mainManipulator = new osgEarth::Util::EarthManipulator; viewer.setCameraManipulator(mainManipulator); // run viewer.setUpViewInWindow(100, 100, 800, 600); viewer.run(); } return 0; }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有