• osgEarth示例分析——osgearth_graticule


    前言

    本示例最具有借鉴的功能:绘制网格、网格上的文字显示、拾取地球的坐标。在地球网格示例中,可以设置4种网格。执行命令如下: 

    1. // --geodetic
    2. osgearth_graticuled.exe --geodetic earth_image\china-simple.earth
    3. // --utm
    4. osgearth_graticuled.exe --utm earth_image\china-simple.earth
    5. // --mgrs
    6. osgearth_graticuled.exe --mgrs earth_image\china-simple.earth
    7. // --gars
    8. osgearth_graticuled.exe --gars earth_image\china-simple.earth

    运行状态如下:

    --geodetic 显示经纬网格,且左上角是经纬高,WGS84坐标系下。

    --utm 地球上显示的字符,左上角显示坐标信息,WGS84坐标系

     --utm 仅左上角显示坐标信息,高程为负值,是因为没有添加高程值,WGS84坐标系

     

    --utm 仅左上角显示坐标信息,高程为负值,是因为没有添加高程值,WGS84坐标系 

     

    类结构分析

    不同的坐标系网格图层,适用不同的坐标格式化方式。

    GARS坐标系:“GARS”经常作为“Global Area Reference System”的缩写来使用,中文表示:“全球区域参考系统”。

    Geodetic坐标系: 是一种地球参考系和地心坐标系。它有WGS60、WGS66、WGS72、WGS84等,是全球定位系统(GPS)的参考构架。

    UTM坐标系:UTM(Universal Transverse Mercator Grid System,通用横墨卡托格网系统)坐标是一种平面直角坐标,这种坐标格网系统及其所依据的投影已经广泛用于地形图,作为卫星影像和自然资源数据库的参考格网以及要求精确定位的其他应用。

    MGRS坐标系:军事格网参考系 (MGRS) 是一种基于格网的参考系,用于在通用横轴墨卡托投影 (UTM) 和通用极方位立体投影 (UPS) 格网系中以字母数字字符串的形式表示位置。与定义特定点不同,MGRS 坐标定义的是地球表面上的某个区域。完全限定的 MGRS 字符串长度为 15 个字符,由以下三个部分组成:格网区域标识、100,000 平方米标识符以及东移/北移。

    左上角显示经纬度信息的ui控件关系图:

     代码分析

    1. #include
    2. #include
    3. #include
    4. #include
    5. #include // 地图节点
    6. #include // 地球操作器
    7. #include // 将鼠标下的地图坐标打印到LabelControl中的工具。
    8. #include // 将坐标数据格式化为MGRS。
    9. #include // 格式化大地坐标(纬度/经度)。
    10. #include // 处理网格
    11. #include // MGRS网格
    12. #include // UTM网格
    13. #include // GARS网格
    14. using namespace osgEarth::Util;
    15. using namespace osgEarth::Annotation;
    16. int
    17. usage( const std::string& msg )
    18. {
    19. OE_NOTICE
    20. << msg << std::endl
    21. << "USAGE: osgearth_graticule [options] file.earth" << std::endl
    22. << " --geodetic : display a Lat/Long graticule" << std::endl
    23. << " --utm : display a UTM graticule" << std::endl
    24. << " --mgrs : display an MGRS graticule" << std::endl
    25. << " --gars : display a GARS graticule" << std::endl;
    26. return -1;
    27. }
    28. //------------------------------------------------------------------------
    29. int
    30. main(int argc, char** argv)
    31. {
    32. // 执行时,程序名 + earth路径
    33. osg::ArgumentParser arguments(&argc,argv);
    34. osgViewer::Viewer viewer(arguments);
    35. // parse command line:
    36. bool isUTM = arguments.read("--utm");
    37. bool isMGRS = arguments.read("--mgrs");
    38. bool isGeodetic = arguments.read("--geodetic");
    39. bool isGARS = arguments.read("--gars");
    40. // load the .earth file from the command line.
    41. MapNode* mapNode = MapNode::load( arguments );
    42. if ( !mapNode )
    43. return usage( "Failed to load a map from the .earth file" );
    44. // install our manipulator:
    45. viewer.setCameraManipulator( new EarthManipulator() );
    46. // root scene graph:
    47. osg::Group* root = new osg::Group();
    48. root->addChild( mapNode );
    49. // 坐标格式器的接口类
    50. Formatter* formatter = 0L;
    51. if ( isUTM )
    52. {
    53. UTMGraticule* gr = new UTMGraticule(); // UTM网格
    54. mapNode->getMap()->addLayer(gr); // 将UTM网格加入到图层
    55. formatter = new MGRSFormatter();
    56. std::cout << "isUTM,Universal Transverse Mercator Grid System,通用横墨卡托格网系统" << std::endl;
    57. }
    58. else if ( isMGRS )
    59. {
    60. MGRSGraticule* gr = new MGRSGraticule();
    61. mapNode->getMap()->addLayer(gr);
    62. formatter = new MGRSFormatter();
    63. std::cout << "isMGRS,军事格网参考系 (MGRS) " << std::endl;
    64. }
    65. else if ( isGARS )
    66. {
    67. GARSGraticule* gr = new GARSGraticule();
    68. mapNode->getMap()->addLayer(gr);
    69. formatter = new LatLongFormatter();
    70. std::cout << "isGARS: Global Area Reference System--全球区域参考系统" << std::endl;
    71. }
    72. else // if ( isGeodetic )
    73. {
    74. GeodeticGraticule* gr = new GeodeticGraticule();
    75. mapNode->getMap()->addLayer(gr);
    76. formatter = new LatLongFormatter();
    77. std::cout << "isGeodetic,大地测量地心坐标系" << std::endl;
    78. }
    79. // mouse coordinate readout:
    80. ControlCanvas* canvas = new ControlCanvas();// 将控件与OSG视图关联对象
    81. root->addChild( canvas );
    82. VBox* vbox = new VBox();// 垂直布局,垂直堆叠控件的容器。
    83. canvas->addControl( vbox );
    84. LabelControl* readout = new LabelControl();// 包含字符串的控件
    85. vbox->addControl( readout );
    86. MouseCoordsTool* tool = new MouseCoordsTool( mapNode );//将鼠标下地图坐标写入控件
    87. tool->addCallback( new MouseCoordsLabelCallback(readout, formatter) );
    88. viewer.addEventHandler( tool );
    89. // disable the small-feature culling
    90. viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f);
    91. // set a near/far ratio that is smaller than the default. This allows us to get
    92. // closer to the ground without near clipping. If you need more, use --logdepth
    93. viewer.getCamera()->setNearFarRatio(0.0001);
    94. // finalize setup and run.
    95. viewer.setSceneData( root );
    96. viewer.addEventHandler(new osgViewer::StatsHandler());
    97. viewer.addEventHandler(new osgViewer::WindowSizeHandler());
    98. viewer.addEventHandler(new osgViewer::ThreadingHandler());
    99. viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
    100. return viewer.run();
    101. }

  • 相关阅读:
    产品经理基础-10运营平台端产品设计(完结~撒花~)
    vue3 rerfs
    使用Go构建一个Postgres流平台
    什么是ChatGPT
    cpp primer plus笔记07-内存模型和命名空间
    显示屏分辨率计算
    【寒枫顾辞老航小说传】第一回:梦回大唐
    项目分享:新年可以做的副业项目,红包封面制作
    vue的子组件
    git 新建 branch 推送 到服务器
  • 原文地址:https://blog.csdn.net/qq_34732729/article/details/128020003